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
|
---|---|---|---|---|---|---|
msteindorfer/criterion | src/main/java/io/usethesource/criterion/impl/persistent/pcollections/PcollectionsValueFactory.java | // Path: src/main/java/io/usethesource/criterion/api/JmhMap.java
// public interface JmhMap extends Iterable<JmhValue>, JmhValue {
//
// public boolean isEmpty();
//
// public int size();
//
// public JmhMap put(JmhValue key, JmhValue value);
//
// public JmhMap removeKey(JmhValue key);
//
// /**
// * @return the value that is mapped to this key, or null if no such value exists
// */
// public JmhValue get(JmhValue key);
//
// public boolean containsKey(JmhValue key);
//
// public boolean containsValue(JmhValue value);
//
// /**
// * @return an iterator over the keys of the map
// */
// @Override
// public Iterator<JmhValue> iterator();
//
// /**
// * @return an iterator over the values of the map
// */
// public Iterator<JmhValue> valueIterator();
//
// /**
// * @return an iterator over the keys-value pairs of the map
// */
// public Iterator<Entry<JmhValue, JmhValue>> entryIterator();
//
// public static interface Builder extends JmhBuilder {
//
// void put(JmhValue key, JmhValue value);
//
// void putAll(JmhMap map);
//
// void putAll(Map<JmhValue, JmhValue> map);
//
// @Override
// JmhMap done();
//
// }
//
// }
//
// Path: src/main/java/io/usethesource/criterion/api/JmhSet.java
// public interface JmhSet extends JmhValue, Iterable<JmhValue> {
//
// boolean isEmpty();
//
// int size();
//
// boolean contains(JmhValue element);
//
// JmhSet insert(JmhValue element);
//
// JmhSet delete(JmhValue elem);
//
// default boolean subsetOf(JmhSet other) {
// throw new UnsupportedOperationException();
// }
//
// default JmhSet union(JmhSet other) {
// throw new UnsupportedOperationException();
// }
//
// default JmhSet subtract(JmhSet other) {
// throw new UnsupportedOperationException();
// }
//
// default JmhSet intersect(JmhSet other) {
// throw new UnsupportedOperationException();
// }
//
// @Override
// Iterator<JmhValue> iterator();
//
// @Deprecated
// java.util.Set<JmhValue> asJavaSet();
//
// interface Builder extends JmhBuilder {
//
// @Deprecated
// default void insert(JmhValue value) {
// insert(new JmhValue[]{value});
// }
//
// void insert(JmhValue... v);
//
// void insertAll(Iterable<? extends JmhValue> collection);
//
// @Override
// JmhSet done();
//
// }
//
// }
//
// Path: src/main/java/io/usethesource/criterion/api/JmhValueFactory.java
// public interface JmhValueFactory {
//
// static RuntimeException FACTORY_NOT_YET_IMPLEMENTED_EXCEPTION =
// new UnsupportedOperationException("Not yet implemented.");
//
// // default JmhSet set() {
// // return setBuilder().done();
// // }
//
// default JmhSet.Builder setBuilder() {
// throw FACTORY_NOT_YET_IMPLEMENTED_EXCEPTION;
// }
//
// // default JmhMap map() {
// // return mapBuilder().done();
// // }
//
// default JmhMap.Builder mapBuilder() {
// throw FACTORY_NOT_YET_IMPLEMENTED_EXCEPTION;
// }
//
// // default JmhSetMultimap setMulimap() {
// // return setMultimapBuilder().done();
// // }
//
// default JmhSetMultimap.Builder setMultimapBuilder() {
// throw FACTORY_NOT_YET_IMPLEMENTED_EXCEPTION;
// }
//
// }
| import io.usethesource.criterion.api.JmhMap;
import io.usethesource.criterion.api.JmhSet;
import io.usethesource.criterion.api.JmhValueFactory; | /**
* Copyright (c) Michael Steindorfer <Centrum Wiskunde & Informatica> and Contributors.
* All rights reserved.
*
* This file is licensed under the BSD 2-Clause License, which accompanies this project
* and is available under https://opensource.org/licenses/BSD-2-Clause.
*/
package io.usethesource.criterion.impl.persistent.pcollections;
public class PcollectionsValueFactory implements JmhValueFactory {
@Override
public JmhSet.Builder setBuilder() {
return new PcollectionsSetBuilder();
}
@Override | // Path: src/main/java/io/usethesource/criterion/api/JmhMap.java
// public interface JmhMap extends Iterable<JmhValue>, JmhValue {
//
// public boolean isEmpty();
//
// public int size();
//
// public JmhMap put(JmhValue key, JmhValue value);
//
// public JmhMap removeKey(JmhValue key);
//
// /**
// * @return the value that is mapped to this key, or null if no such value exists
// */
// public JmhValue get(JmhValue key);
//
// public boolean containsKey(JmhValue key);
//
// public boolean containsValue(JmhValue value);
//
// /**
// * @return an iterator over the keys of the map
// */
// @Override
// public Iterator<JmhValue> iterator();
//
// /**
// * @return an iterator over the values of the map
// */
// public Iterator<JmhValue> valueIterator();
//
// /**
// * @return an iterator over the keys-value pairs of the map
// */
// public Iterator<Entry<JmhValue, JmhValue>> entryIterator();
//
// public static interface Builder extends JmhBuilder {
//
// void put(JmhValue key, JmhValue value);
//
// void putAll(JmhMap map);
//
// void putAll(Map<JmhValue, JmhValue> map);
//
// @Override
// JmhMap done();
//
// }
//
// }
//
// Path: src/main/java/io/usethesource/criterion/api/JmhSet.java
// public interface JmhSet extends JmhValue, Iterable<JmhValue> {
//
// boolean isEmpty();
//
// int size();
//
// boolean contains(JmhValue element);
//
// JmhSet insert(JmhValue element);
//
// JmhSet delete(JmhValue elem);
//
// default boolean subsetOf(JmhSet other) {
// throw new UnsupportedOperationException();
// }
//
// default JmhSet union(JmhSet other) {
// throw new UnsupportedOperationException();
// }
//
// default JmhSet subtract(JmhSet other) {
// throw new UnsupportedOperationException();
// }
//
// default JmhSet intersect(JmhSet other) {
// throw new UnsupportedOperationException();
// }
//
// @Override
// Iterator<JmhValue> iterator();
//
// @Deprecated
// java.util.Set<JmhValue> asJavaSet();
//
// interface Builder extends JmhBuilder {
//
// @Deprecated
// default void insert(JmhValue value) {
// insert(new JmhValue[]{value});
// }
//
// void insert(JmhValue... v);
//
// void insertAll(Iterable<? extends JmhValue> collection);
//
// @Override
// JmhSet done();
//
// }
//
// }
//
// Path: src/main/java/io/usethesource/criterion/api/JmhValueFactory.java
// public interface JmhValueFactory {
//
// static RuntimeException FACTORY_NOT_YET_IMPLEMENTED_EXCEPTION =
// new UnsupportedOperationException("Not yet implemented.");
//
// // default JmhSet set() {
// // return setBuilder().done();
// // }
//
// default JmhSet.Builder setBuilder() {
// throw FACTORY_NOT_YET_IMPLEMENTED_EXCEPTION;
// }
//
// // default JmhMap map() {
// // return mapBuilder().done();
// // }
//
// default JmhMap.Builder mapBuilder() {
// throw FACTORY_NOT_YET_IMPLEMENTED_EXCEPTION;
// }
//
// // default JmhSetMultimap setMulimap() {
// // return setMultimapBuilder().done();
// // }
//
// default JmhSetMultimap.Builder setMultimapBuilder() {
// throw FACTORY_NOT_YET_IMPLEMENTED_EXCEPTION;
// }
//
// }
// Path: src/main/java/io/usethesource/criterion/impl/persistent/pcollections/PcollectionsValueFactory.java
import io.usethesource.criterion.api.JmhMap;
import io.usethesource.criterion.api.JmhSet;
import io.usethesource.criterion.api.JmhValueFactory;
/**
* Copyright (c) Michael Steindorfer <Centrum Wiskunde & Informatica> and Contributors.
* All rights reserved.
*
* This file is licensed under the BSD 2-Clause License, which accompanies this project
* and is available under https://opensource.org/licenses/BSD-2-Clause.
*/
package io.usethesource.criterion.impl.persistent.pcollections;
public class PcollectionsValueFactory implements JmhValueFactory {
@Override
public JmhSet.Builder setBuilder() {
return new PcollectionsSetBuilder();
}
@Override | public JmhMap.Builder mapBuilder() { |
msteindorfer/criterion | src/main/java/io/usethesource/criterion/BenchmarkUtils.java | // Path: src/main/java/io/usethesource/criterion/api/JmhValueFactory.java
// public interface JmhValueFactory {
//
// static RuntimeException FACTORY_NOT_YET_IMPLEMENTED_EXCEPTION =
// new UnsupportedOperationException("Not yet implemented.");
//
// // default JmhSet set() {
// // return setBuilder().done();
// // }
//
// default JmhSet.Builder setBuilder() {
// throw FACTORY_NOT_YET_IMPLEMENTED_EXCEPTION;
// }
//
// // default JmhMap map() {
// // return mapBuilder().done();
// // }
//
// default JmhMap.Builder mapBuilder() {
// throw FACTORY_NOT_YET_IMPLEMENTED_EXCEPTION;
// }
//
// // default JmhSetMultimap setMulimap() {
// // return setMultimapBuilder().done();
// // }
//
// default JmhSetMultimap.Builder setMultimapBuilder() {
// throw FACTORY_NOT_YET_IMPLEMENTED_EXCEPTION;
// }
//
// }
//
// Path: src/main/java/io/usethesource/criterion/impl/immutable/guava/ImmutableGuavaValueFactory.java
// public class ImmutableGuavaValueFactory implements JmhValueFactory {
//
// public ImmutableGuavaValueFactory() {
// }
//
// @Override
// public JmhSet.Builder setBuilder() {
// return new ImmutableGuavaSetBuilder();
// }
//
// @Override
// public JmhMap.Builder mapBuilder() {
// return new ImmutableGuavaMapBuilder();
// }
//
// @Override
// public JmhSetMultimap.Builder setMultimapBuilder() {
// return new ImmutableGuavaSetMultimapBuilder();
// }
//
// @Override
// public String toString() {
// return "VF_GUAVA_IMMUTABLE";
// }
//
// }
//
// Path: src/main/java/io/usethesource/criterion/impl/persistent/paguro/PaguroValueFactory.java
// public class PaguroValueFactory implements JmhValueFactory {
//
// @Override
// public JmhSet.Builder setBuilder() {
// return new PaguroSetBuilder();
// }
//
// @Override
// public JmhMap.Builder mapBuilder() {
// return new PaguroMapBuilder();
// }
//
// @Override
// public String toString() {
// return "VF_PAGURO";
// }
//
// }
//
// Path: src/main/java/io/usethesource/criterion/impl/persistent/vavr/VavrValueFactory.java
// public class VavrValueFactory implements JmhValueFactory {
//
// @Override
// public JmhSet.Builder setBuilder() {
// return new VavrSetBuilder();
// }
//
// @Override
// public JmhMap.Builder mapBuilder() {
// return new VavrMapBuilder();
// }
//
// @Override
// public String toString() {
// return "VF_VAVR";
// }
//
// }
| import java.util.Arrays;
import java.util.Random;
import io.usethesource.capsule.core.PersistentBidirectionalTrieSetMultimap;
import io.usethesource.capsule.core.PersistentTrieMap;
import io.usethesource.capsule.core.PersistentTrieSet;
import io.usethesource.capsule.core.PersistentTrieSetMultimap;
import io.usethesource.capsule.experimental.heterogeneous.TrieMap_5Bits_Heterogeneous_BleedingEdge;
import io.usethesource.capsule.experimental.memoized.TrieMap_5Bits_Memoized_LazyHashCode;
import io.usethesource.capsule.experimental.memoized.TrieSet_5Bits_Memoized_LazyHashCode;
import io.usethesource.capsule.experimental.multimap.TrieSetMultimap_HHAMT;
import io.usethesource.capsule.experimental.multimap.TrieSetMultimap_HHAMT_Specialized;
import io.usethesource.capsule.experimental.specialized.TrieMap_5Bits_Spec0To8;
import io.usethesource.capsule.experimental.specialized.TrieSet_5Bits_Spec0To8;
import io.usethesource.criterion.api.JmhValueFactory;
import io.usethesource.criterion.impl.immutable.guava.ImmutableGuavaValueFactory;
import io.usethesource.criterion.impl.persistent.paguro.PaguroValueFactory;
import io.usethesource.criterion.impl.persistent.vavr.VavrValueFactory; | /**
* Copyright (c) Michael Steindorfer <Centrum Wiskunde & Informatica> and Contributors.
* All rights reserved.
*
* This file is licensed under the BSD 2-Clause License, which accompanies this project
* and is available under https://opensource.org/licenses/BSD-2-Clause.
*/
package io.usethesource.criterion;
public class BenchmarkUtils {
public enum ValueFactoryFactory {
VF_CLOJURE {
@Override | // Path: src/main/java/io/usethesource/criterion/api/JmhValueFactory.java
// public interface JmhValueFactory {
//
// static RuntimeException FACTORY_NOT_YET_IMPLEMENTED_EXCEPTION =
// new UnsupportedOperationException("Not yet implemented.");
//
// // default JmhSet set() {
// // return setBuilder().done();
// // }
//
// default JmhSet.Builder setBuilder() {
// throw FACTORY_NOT_YET_IMPLEMENTED_EXCEPTION;
// }
//
// // default JmhMap map() {
// // return mapBuilder().done();
// // }
//
// default JmhMap.Builder mapBuilder() {
// throw FACTORY_NOT_YET_IMPLEMENTED_EXCEPTION;
// }
//
// // default JmhSetMultimap setMulimap() {
// // return setMultimapBuilder().done();
// // }
//
// default JmhSetMultimap.Builder setMultimapBuilder() {
// throw FACTORY_NOT_YET_IMPLEMENTED_EXCEPTION;
// }
//
// }
//
// Path: src/main/java/io/usethesource/criterion/impl/immutable/guava/ImmutableGuavaValueFactory.java
// public class ImmutableGuavaValueFactory implements JmhValueFactory {
//
// public ImmutableGuavaValueFactory() {
// }
//
// @Override
// public JmhSet.Builder setBuilder() {
// return new ImmutableGuavaSetBuilder();
// }
//
// @Override
// public JmhMap.Builder mapBuilder() {
// return new ImmutableGuavaMapBuilder();
// }
//
// @Override
// public JmhSetMultimap.Builder setMultimapBuilder() {
// return new ImmutableGuavaSetMultimapBuilder();
// }
//
// @Override
// public String toString() {
// return "VF_GUAVA_IMMUTABLE";
// }
//
// }
//
// Path: src/main/java/io/usethesource/criterion/impl/persistent/paguro/PaguroValueFactory.java
// public class PaguroValueFactory implements JmhValueFactory {
//
// @Override
// public JmhSet.Builder setBuilder() {
// return new PaguroSetBuilder();
// }
//
// @Override
// public JmhMap.Builder mapBuilder() {
// return new PaguroMapBuilder();
// }
//
// @Override
// public String toString() {
// return "VF_PAGURO";
// }
//
// }
//
// Path: src/main/java/io/usethesource/criterion/impl/persistent/vavr/VavrValueFactory.java
// public class VavrValueFactory implements JmhValueFactory {
//
// @Override
// public JmhSet.Builder setBuilder() {
// return new VavrSetBuilder();
// }
//
// @Override
// public JmhMap.Builder mapBuilder() {
// return new VavrMapBuilder();
// }
//
// @Override
// public String toString() {
// return "VF_VAVR";
// }
//
// }
// Path: src/main/java/io/usethesource/criterion/BenchmarkUtils.java
import java.util.Arrays;
import java.util.Random;
import io.usethesource.capsule.core.PersistentBidirectionalTrieSetMultimap;
import io.usethesource.capsule.core.PersistentTrieMap;
import io.usethesource.capsule.core.PersistentTrieSet;
import io.usethesource.capsule.core.PersistentTrieSetMultimap;
import io.usethesource.capsule.experimental.heterogeneous.TrieMap_5Bits_Heterogeneous_BleedingEdge;
import io.usethesource.capsule.experimental.memoized.TrieMap_5Bits_Memoized_LazyHashCode;
import io.usethesource.capsule.experimental.memoized.TrieSet_5Bits_Memoized_LazyHashCode;
import io.usethesource.capsule.experimental.multimap.TrieSetMultimap_HHAMT;
import io.usethesource.capsule.experimental.multimap.TrieSetMultimap_HHAMT_Specialized;
import io.usethesource.capsule.experimental.specialized.TrieMap_5Bits_Spec0To8;
import io.usethesource.capsule.experimental.specialized.TrieSet_5Bits_Spec0To8;
import io.usethesource.criterion.api.JmhValueFactory;
import io.usethesource.criterion.impl.immutable.guava.ImmutableGuavaValueFactory;
import io.usethesource.criterion.impl.persistent.paguro.PaguroValueFactory;
import io.usethesource.criterion.impl.persistent.vavr.VavrValueFactory;
/**
* Copyright (c) Michael Steindorfer <Centrum Wiskunde & Informatica> and Contributors.
* All rights reserved.
*
* This file is licensed under the BSD 2-Clause License, which accompanies this project
* and is available under https://opensource.org/licenses/BSD-2-Clause.
*/
package io.usethesource.criterion;
public class BenchmarkUtils {
public enum ValueFactoryFactory {
VF_CLOJURE {
@Override | public JmhValueFactory getInstance() { |
msteindorfer/criterion | src/main/java/io/usethesource/criterion/BenchmarkUtils.java | // Path: src/main/java/io/usethesource/criterion/api/JmhValueFactory.java
// public interface JmhValueFactory {
//
// static RuntimeException FACTORY_NOT_YET_IMPLEMENTED_EXCEPTION =
// new UnsupportedOperationException("Not yet implemented.");
//
// // default JmhSet set() {
// // return setBuilder().done();
// // }
//
// default JmhSet.Builder setBuilder() {
// throw FACTORY_NOT_YET_IMPLEMENTED_EXCEPTION;
// }
//
// // default JmhMap map() {
// // return mapBuilder().done();
// // }
//
// default JmhMap.Builder mapBuilder() {
// throw FACTORY_NOT_YET_IMPLEMENTED_EXCEPTION;
// }
//
// // default JmhSetMultimap setMulimap() {
// // return setMultimapBuilder().done();
// // }
//
// default JmhSetMultimap.Builder setMultimapBuilder() {
// throw FACTORY_NOT_YET_IMPLEMENTED_EXCEPTION;
// }
//
// }
//
// Path: src/main/java/io/usethesource/criterion/impl/immutable/guava/ImmutableGuavaValueFactory.java
// public class ImmutableGuavaValueFactory implements JmhValueFactory {
//
// public ImmutableGuavaValueFactory() {
// }
//
// @Override
// public JmhSet.Builder setBuilder() {
// return new ImmutableGuavaSetBuilder();
// }
//
// @Override
// public JmhMap.Builder mapBuilder() {
// return new ImmutableGuavaMapBuilder();
// }
//
// @Override
// public JmhSetMultimap.Builder setMultimapBuilder() {
// return new ImmutableGuavaSetMultimapBuilder();
// }
//
// @Override
// public String toString() {
// return "VF_GUAVA_IMMUTABLE";
// }
//
// }
//
// Path: src/main/java/io/usethesource/criterion/impl/persistent/paguro/PaguroValueFactory.java
// public class PaguroValueFactory implements JmhValueFactory {
//
// @Override
// public JmhSet.Builder setBuilder() {
// return new PaguroSetBuilder();
// }
//
// @Override
// public JmhMap.Builder mapBuilder() {
// return new PaguroMapBuilder();
// }
//
// @Override
// public String toString() {
// return "VF_PAGURO";
// }
//
// }
//
// Path: src/main/java/io/usethesource/criterion/impl/persistent/vavr/VavrValueFactory.java
// public class VavrValueFactory implements JmhValueFactory {
//
// @Override
// public JmhSet.Builder setBuilder() {
// return new VavrSetBuilder();
// }
//
// @Override
// public JmhMap.Builder mapBuilder() {
// return new VavrMapBuilder();
// }
//
// @Override
// public String toString() {
// return "VF_VAVR";
// }
//
// }
| import java.util.Arrays;
import java.util.Random;
import io.usethesource.capsule.core.PersistentBidirectionalTrieSetMultimap;
import io.usethesource.capsule.core.PersistentTrieMap;
import io.usethesource.capsule.core.PersistentTrieSet;
import io.usethesource.capsule.core.PersistentTrieSetMultimap;
import io.usethesource.capsule.experimental.heterogeneous.TrieMap_5Bits_Heterogeneous_BleedingEdge;
import io.usethesource.capsule.experimental.memoized.TrieMap_5Bits_Memoized_LazyHashCode;
import io.usethesource.capsule.experimental.memoized.TrieSet_5Bits_Memoized_LazyHashCode;
import io.usethesource.capsule.experimental.multimap.TrieSetMultimap_HHAMT;
import io.usethesource.capsule.experimental.multimap.TrieSetMultimap_HHAMT_Specialized;
import io.usethesource.capsule.experimental.specialized.TrieMap_5Bits_Spec0To8;
import io.usethesource.capsule.experimental.specialized.TrieSet_5Bits_Spec0To8;
import io.usethesource.criterion.api.JmhValueFactory;
import io.usethesource.criterion.impl.immutable.guava.ImmutableGuavaValueFactory;
import io.usethesource.criterion.impl.persistent.paguro.PaguroValueFactory;
import io.usethesource.criterion.impl.persistent.vavr.VavrValueFactory; | public enum ValueFactoryFactory {
VF_CLOJURE {
@Override
public JmhValueFactory getInstance() {
return new io.usethesource.criterion.impl.persistent.clojure.ClojureValueFactory();
}
},
VF_SCALA {
@Override
public JmhValueFactory getInstance() {
return new io.usethesource.criterion.impl.persistent.scala.ScalaValueFactory();
}
},
VF_CHAMP {
@Override
public JmhValueFactory getInstance() {
return new io.usethesource.criterion.impl.persistent.champ.ChampValueFactory(
PersistentTrieSet.class, PersistentTrieMap.class, PersistentTrieSetMultimap.class);
}
},
VF_CHAMP_SPECIALIZED {
@Override
public JmhValueFactory getInstance() {
return new io.usethesource.criterion.impl.persistent.champ.ChampValueFactory(
TrieSet_5Bits_Spec0To8.class, TrieMap_5Bits_Spec0To8.class, null);
}
},
VF_VAVR {
@Override
public JmhValueFactory getInstance() { | // Path: src/main/java/io/usethesource/criterion/api/JmhValueFactory.java
// public interface JmhValueFactory {
//
// static RuntimeException FACTORY_NOT_YET_IMPLEMENTED_EXCEPTION =
// new UnsupportedOperationException("Not yet implemented.");
//
// // default JmhSet set() {
// // return setBuilder().done();
// // }
//
// default JmhSet.Builder setBuilder() {
// throw FACTORY_NOT_YET_IMPLEMENTED_EXCEPTION;
// }
//
// // default JmhMap map() {
// // return mapBuilder().done();
// // }
//
// default JmhMap.Builder mapBuilder() {
// throw FACTORY_NOT_YET_IMPLEMENTED_EXCEPTION;
// }
//
// // default JmhSetMultimap setMulimap() {
// // return setMultimapBuilder().done();
// // }
//
// default JmhSetMultimap.Builder setMultimapBuilder() {
// throw FACTORY_NOT_YET_IMPLEMENTED_EXCEPTION;
// }
//
// }
//
// Path: src/main/java/io/usethesource/criterion/impl/immutable/guava/ImmutableGuavaValueFactory.java
// public class ImmutableGuavaValueFactory implements JmhValueFactory {
//
// public ImmutableGuavaValueFactory() {
// }
//
// @Override
// public JmhSet.Builder setBuilder() {
// return new ImmutableGuavaSetBuilder();
// }
//
// @Override
// public JmhMap.Builder mapBuilder() {
// return new ImmutableGuavaMapBuilder();
// }
//
// @Override
// public JmhSetMultimap.Builder setMultimapBuilder() {
// return new ImmutableGuavaSetMultimapBuilder();
// }
//
// @Override
// public String toString() {
// return "VF_GUAVA_IMMUTABLE";
// }
//
// }
//
// Path: src/main/java/io/usethesource/criterion/impl/persistent/paguro/PaguroValueFactory.java
// public class PaguroValueFactory implements JmhValueFactory {
//
// @Override
// public JmhSet.Builder setBuilder() {
// return new PaguroSetBuilder();
// }
//
// @Override
// public JmhMap.Builder mapBuilder() {
// return new PaguroMapBuilder();
// }
//
// @Override
// public String toString() {
// return "VF_PAGURO";
// }
//
// }
//
// Path: src/main/java/io/usethesource/criterion/impl/persistent/vavr/VavrValueFactory.java
// public class VavrValueFactory implements JmhValueFactory {
//
// @Override
// public JmhSet.Builder setBuilder() {
// return new VavrSetBuilder();
// }
//
// @Override
// public JmhMap.Builder mapBuilder() {
// return new VavrMapBuilder();
// }
//
// @Override
// public String toString() {
// return "VF_VAVR";
// }
//
// }
// Path: src/main/java/io/usethesource/criterion/BenchmarkUtils.java
import java.util.Arrays;
import java.util.Random;
import io.usethesource.capsule.core.PersistentBidirectionalTrieSetMultimap;
import io.usethesource.capsule.core.PersistentTrieMap;
import io.usethesource.capsule.core.PersistentTrieSet;
import io.usethesource.capsule.core.PersistentTrieSetMultimap;
import io.usethesource.capsule.experimental.heterogeneous.TrieMap_5Bits_Heterogeneous_BleedingEdge;
import io.usethesource.capsule.experimental.memoized.TrieMap_5Bits_Memoized_LazyHashCode;
import io.usethesource.capsule.experimental.memoized.TrieSet_5Bits_Memoized_LazyHashCode;
import io.usethesource.capsule.experimental.multimap.TrieSetMultimap_HHAMT;
import io.usethesource.capsule.experimental.multimap.TrieSetMultimap_HHAMT_Specialized;
import io.usethesource.capsule.experimental.specialized.TrieMap_5Bits_Spec0To8;
import io.usethesource.capsule.experimental.specialized.TrieSet_5Bits_Spec0To8;
import io.usethesource.criterion.api.JmhValueFactory;
import io.usethesource.criterion.impl.immutable.guava.ImmutableGuavaValueFactory;
import io.usethesource.criterion.impl.persistent.paguro.PaguroValueFactory;
import io.usethesource.criterion.impl.persistent.vavr.VavrValueFactory;
public enum ValueFactoryFactory {
VF_CLOJURE {
@Override
public JmhValueFactory getInstance() {
return new io.usethesource.criterion.impl.persistent.clojure.ClojureValueFactory();
}
},
VF_SCALA {
@Override
public JmhValueFactory getInstance() {
return new io.usethesource.criterion.impl.persistent.scala.ScalaValueFactory();
}
},
VF_CHAMP {
@Override
public JmhValueFactory getInstance() {
return new io.usethesource.criterion.impl.persistent.champ.ChampValueFactory(
PersistentTrieSet.class, PersistentTrieMap.class, PersistentTrieSetMultimap.class);
}
},
VF_CHAMP_SPECIALIZED {
@Override
public JmhValueFactory getInstance() {
return new io.usethesource.criterion.impl.persistent.champ.ChampValueFactory(
TrieSet_5Bits_Spec0To8.class, TrieMap_5Bits_Spec0To8.class, null);
}
},
VF_VAVR {
@Override
public JmhValueFactory getInstance() { | return new VavrValueFactory(); |
msteindorfer/criterion | src/main/java/io/usethesource/criterion/BenchmarkUtils.java | // Path: src/main/java/io/usethesource/criterion/api/JmhValueFactory.java
// public interface JmhValueFactory {
//
// static RuntimeException FACTORY_NOT_YET_IMPLEMENTED_EXCEPTION =
// new UnsupportedOperationException("Not yet implemented.");
//
// // default JmhSet set() {
// // return setBuilder().done();
// // }
//
// default JmhSet.Builder setBuilder() {
// throw FACTORY_NOT_YET_IMPLEMENTED_EXCEPTION;
// }
//
// // default JmhMap map() {
// // return mapBuilder().done();
// // }
//
// default JmhMap.Builder mapBuilder() {
// throw FACTORY_NOT_YET_IMPLEMENTED_EXCEPTION;
// }
//
// // default JmhSetMultimap setMulimap() {
// // return setMultimapBuilder().done();
// // }
//
// default JmhSetMultimap.Builder setMultimapBuilder() {
// throw FACTORY_NOT_YET_IMPLEMENTED_EXCEPTION;
// }
//
// }
//
// Path: src/main/java/io/usethesource/criterion/impl/immutable/guava/ImmutableGuavaValueFactory.java
// public class ImmutableGuavaValueFactory implements JmhValueFactory {
//
// public ImmutableGuavaValueFactory() {
// }
//
// @Override
// public JmhSet.Builder setBuilder() {
// return new ImmutableGuavaSetBuilder();
// }
//
// @Override
// public JmhMap.Builder mapBuilder() {
// return new ImmutableGuavaMapBuilder();
// }
//
// @Override
// public JmhSetMultimap.Builder setMultimapBuilder() {
// return new ImmutableGuavaSetMultimapBuilder();
// }
//
// @Override
// public String toString() {
// return "VF_GUAVA_IMMUTABLE";
// }
//
// }
//
// Path: src/main/java/io/usethesource/criterion/impl/persistent/paguro/PaguroValueFactory.java
// public class PaguroValueFactory implements JmhValueFactory {
//
// @Override
// public JmhSet.Builder setBuilder() {
// return new PaguroSetBuilder();
// }
//
// @Override
// public JmhMap.Builder mapBuilder() {
// return new PaguroMapBuilder();
// }
//
// @Override
// public String toString() {
// return "VF_PAGURO";
// }
//
// }
//
// Path: src/main/java/io/usethesource/criterion/impl/persistent/vavr/VavrValueFactory.java
// public class VavrValueFactory implements JmhValueFactory {
//
// @Override
// public JmhSet.Builder setBuilder() {
// return new VavrSetBuilder();
// }
//
// @Override
// public JmhMap.Builder mapBuilder() {
// return new VavrMapBuilder();
// }
//
// @Override
// public String toString() {
// return "VF_VAVR";
// }
//
// }
| import java.util.Arrays;
import java.util.Random;
import io.usethesource.capsule.core.PersistentBidirectionalTrieSetMultimap;
import io.usethesource.capsule.core.PersistentTrieMap;
import io.usethesource.capsule.core.PersistentTrieSet;
import io.usethesource.capsule.core.PersistentTrieSetMultimap;
import io.usethesource.capsule.experimental.heterogeneous.TrieMap_5Bits_Heterogeneous_BleedingEdge;
import io.usethesource.capsule.experimental.memoized.TrieMap_5Bits_Memoized_LazyHashCode;
import io.usethesource.capsule.experimental.memoized.TrieSet_5Bits_Memoized_LazyHashCode;
import io.usethesource.capsule.experimental.multimap.TrieSetMultimap_HHAMT;
import io.usethesource.capsule.experimental.multimap.TrieSetMultimap_HHAMT_Specialized;
import io.usethesource.capsule.experimental.specialized.TrieMap_5Bits_Spec0To8;
import io.usethesource.capsule.experimental.specialized.TrieSet_5Bits_Spec0To8;
import io.usethesource.criterion.api.JmhValueFactory;
import io.usethesource.criterion.impl.immutable.guava.ImmutableGuavaValueFactory;
import io.usethesource.criterion.impl.persistent.paguro.PaguroValueFactory;
import io.usethesource.criterion.impl.persistent.vavr.VavrValueFactory; | },
VF_SCALA {
@Override
public JmhValueFactory getInstance() {
return new io.usethesource.criterion.impl.persistent.scala.ScalaValueFactory();
}
},
VF_CHAMP {
@Override
public JmhValueFactory getInstance() {
return new io.usethesource.criterion.impl.persistent.champ.ChampValueFactory(
PersistentTrieSet.class, PersistentTrieMap.class, PersistentTrieSetMultimap.class);
}
},
VF_CHAMP_SPECIALIZED {
@Override
public JmhValueFactory getInstance() {
return new io.usethesource.criterion.impl.persistent.champ.ChampValueFactory(
TrieSet_5Bits_Spec0To8.class, TrieMap_5Bits_Spec0To8.class, null);
}
},
VF_VAVR {
@Override
public JmhValueFactory getInstance() {
return new VavrValueFactory();
}
},
VF_PAGURO {
@Override
public JmhValueFactory getInstance() { | // Path: src/main/java/io/usethesource/criterion/api/JmhValueFactory.java
// public interface JmhValueFactory {
//
// static RuntimeException FACTORY_NOT_YET_IMPLEMENTED_EXCEPTION =
// new UnsupportedOperationException("Not yet implemented.");
//
// // default JmhSet set() {
// // return setBuilder().done();
// // }
//
// default JmhSet.Builder setBuilder() {
// throw FACTORY_NOT_YET_IMPLEMENTED_EXCEPTION;
// }
//
// // default JmhMap map() {
// // return mapBuilder().done();
// // }
//
// default JmhMap.Builder mapBuilder() {
// throw FACTORY_NOT_YET_IMPLEMENTED_EXCEPTION;
// }
//
// // default JmhSetMultimap setMulimap() {
// // return setMultimapBuilder().done();
// // }
//
// default JmhSetMultimap.Builder setMultimapBuilder() {
// throw FACTORY_NOT_YET_IMPLEMENTED_EXCEPTION;
// }
//
// }
//
// Path: src/main/java/io/usethesource/criterion/impl/immutable/guava/ImmutableGuavaValueFactory.java
// public class ImmutableGuavaValueFactory implements JmhValueFactory {
//
// public ImmutableGuavaValueFactory() {
// }
//
// @Override
// public JmhSet.Builder setBuilder() {
// return new ImmutableGuavaSetBuilder();
// }
//
// @Override
// public JmhMap.Builder mapBuilder() {
// return new ImmutableGuavaMapBuilder();
// }
//
// @Override
// public JmhSetMultimap.Builder setMultimapBuilder() {
// return new ImmutableGuavaSetMultimapBuilder();
// }
//
// @Override
// public String toString() {
// return "VF_GUAVA_IMMUTABLE";
// }
//
// }
//
// Path: src/main/java/io/usethesource/criterion/impl/persistent/paguro/PaguroValueFactory.java
// public class PaguroValueFactory implements JmhValueFactory {
//
// @Override
// public JmhSet.Builder setBuilder() {
// return new PaguroSetBuilder();
// }
//
// @Override
// public JmhMap.Builder mapBuilder() {
// return new PaguroMapBuilder();
// }
//
// @Override
// public String toString() {
// return "VF_PAGURO";
// }
//
// }
//
// Path: src/main/java/io/usethesource/criterion/impl/persistent/vavr/VavrValueFactory.java
// public class VavrValueFactory implements JmhValueFactory {
//
// @Override
// public JmhSet.Builder setBuilder() {
// return new VavrSetBuilder();
// }
//
// @Override
// public JmhMap.Builder mapBuilder() {
// return new VavrMapBuilder();
// }
//
// @Override
// public String toString() {
// return "VF_VAVR";
// }
//
// }
// Path: src/main/java/io/usethesource/criterion/BenchmarkUtils.java
import java.util.Arrays;
import java.util.Random;
import io.usethesource.capsule.core.PersistentBidirectionalTrieSetMultimap;
import io.usethesource.capsule.core.PersistentTrieMap;
import io.usethesource.capsule.core.PersistentTrieSet;
import io.usethesource.capsule.core.PersistentTrieSetMultimap;
import io.usethesource.capsule.experimental.heterogeneous.TrieMap_5Bits_Heterogeneous_BleedingEdge;
import io.usethesource.capsule.experimental.memoized.TrieMap_5Bits_Memoized_LazyHashCode;
import io.usethesource.capsule.experimental.memoized.TrieSet_5Bits_Memoized_LazyHashCode;
import io.usethesource.capsule.experimental.multimap.TrieSetMultimap_HHAMT;
import io.usethesource.capsule.experimental.multimap.TrieSetMultimap_HHAMT_Specialized;
import io.usethesource.capsule.experimental.specialized.TrieMap_5Bits_Spec0To8;
import io.usethesource.capsule.experimental.specialized.TrieSet_5Bits_Spec0To8;
import io.usethesource.criterion.api.JmhValueFactory;
import io.usethesource.criterion.impl.immutable.guava.ImmutableGuavaValueFactory;
import io.usethesource.criterion.impl.persistent.paguro.PaguroValueFactory;
import io.usethesource.criterion.impl.persistent.vavr.VavrValueFactory;
},
VF_SCALA {
@Override
public JmhValueFactory getInstance() {
return new io.usethesource.criterion.impl.persistent.scala.ScalaValueFactory();
}
},
VF_CHAMP {
@Override
public JmhValueFactory getInstance() {
return new io.usethesource.criterion.impl.persistent.champ.ChampValueFactory(
PersistentTrieSet.class, PersistentTrieMap.class, PersistentTrieSetMultimap.class);
}
},
VF_CHAMP_SPECIALIZED {
@Override
public JmhValueFactory getInstance() {
return new io.usethesource.criterion.impl.persistent.champ.ChampValueFactory(
TrieSet_5Bits_Spec0To8.class, TrieMap_5Bits_Spec0To8.class, null);
}
},
VF_VAVR {
@Override
public JmhValueFactory getInstance() {
return new VavrValueFactory();
}
},
VF_PAGURO {
@Override
public JmhValueFactory getInstance() { | return new PaguroValueFactory(); |
msteindorfer/criterion | src/main/java/io/usethesource/criterion/BenchmarkUtils.java | // Path: src/main/java/io/usethesource/criterion/api/JmhValueFactory.java
// public interface JmhValueFactory {
//
// static RuntimeException FACTORY_NOT_YET_IMPLEMENTED_EXCEPTION =
// new UnsupportedOperationException("Not yet implemented.");
//
// // default JmhSet set() {
// // return setBuilder().done();
// // }
//
// default JmhSet.Builder setBuilder() {
// throw FACTORY_NOT_YET_IMPLEMENTED_EXCEPTION;
// }
//
// // default JmhMap map() {
// // return mapBuilder().done();
// // }
//
// default JmhMap.Builder mapBuilder() {
// throw FACTORY_NOT_YET_IMPLEMENTED_EXCEPTION;
// }
//
// // default JmhSetMultimap setMulimap() {
// // return setMultimapBuilder().done();
// // }
//
// default JmhSetMultimap.Builder setMultimapBuilder() {
// throw FACTORY_NOT_YET_IMPLEMENTED_EXCEPTION;
// }
//
// }
//
// Path: src/main/java/io/usethesource/criterion/impl/immutable/guava/ImmutableGuavaValueFactory.java
// public class ImmutableGuavaValueFactory implements JmhValueFactory {
//
// public ImmutableGuavaValueFactory() {
// }
//
// @Override
// public JmhSet.Builder setBuilder() {
// return new ImmutableGuavaSetBuilder();
// }
//
// @Override
// public JmhMap.Builder mapBuilder() {
// return new ImmutableGuavaMapBuilder();
// }
//
// @Override
// public JmhSetMultimap.Builder setMultimapBuilder() {
// return new ImmutableGuavaSetMultimapBuilder();
// }
//
// @Override
// public String toString() {
// return "VF_GUAVA_IMMUTABLE";
// }
//
// }
//
// Path: src/main/java/io/usethesource/criterion/impl/persistent/paguro/PaguroValueFactory.java
// public class PaguroValueFactory implements JmhValueFactory {
//
// @Override
// public JmhSet.Builder setBuilder() {
// return new PaguroSetBuilder();
// }
//
// @Override
// public JmhMap.Builder mapBuilder() {
// return new PaguroMapBuilder();
// }
//
// @Override
// public String toString() {
// return "VF_PAGURO";
// }
//
// }
//
// Path: src/main/java/io/usethesource/criterion/impl/persistent/vavr/VavrValueFactory.java
// public class VavrValueFactory implements JmhValueFactory {
//
// @Override
// public JmhSet.Builder setBuilder() {
// return new VavrSetBuilder();
// }
//
// @Override
// public JmhMap.Builder mapBuilder() {
// return new VavrMapBuilder();
// }
//
// @Override
// public String toString() {
// return "VF_VAVR";
// }
//
// }
| import java.util.Arrays;
import java.util.Random;
import io.usethesource.capsule.core.PersistentBidirectionalTrieSetMultimap;
import io.usethesource.capsule.core.PersistentTrieMap;
import io.usethesource.capsule.core.PersistentTrieSet;
import io.usethesource.capsule.core.PersistentTrieSetMultimap;
import io.usethesource.capsule.experimental.heterogeneous.TrieMap_5Bits_Heterogeneous_BleedingEdge;
import io.usethesource.capsule.experimental.memoized.TrieMap_5Bits_Memoized_LazyHashCode;
import io.usethesource.capsule.experimental.memoized.TrieSet_5Bits_Memoized_LazyHashCode;
import io.usethesource.capsule.experimental.multimap.TrieSetMultimap_HHAMT;
import io.usethesource.capsule.experimental.multimap.TrieSetMultimap_HHAMT_Specialized;
import io.usethesource.capsule.experimental.specialized.TrieMap_5Bits_Spec0To8;
import io.usethesource.capsule.experimental.specialized.TrieSet_5Bits_Spec0To8;
import io.usethesource.criterion.api.JmhValueFactory;
import io.usethesource.criterion.impl.immutable.guava.ImmutableGuavaValueFactory;
import io.usethesource.criterion.impl.persistent.paguro.PaguroValueFactory;
import io.usethesource.criterion.impl.persistent.vavr.VavrValueFactory; | TrieSet_5Bits_Spec0To8.class, TrieMap_5Bits_Spec0To8.class, null);
}
},
VF_VAVR {
@Override
public JmhValueFactory getInstance() {
return new VavrValueFactory();
}
},
VF_PAGURO {
@Override
public JmhValueFactory getInstance() {
return new PaguroValueFactory();
}
},
VF_DEXX {
@Override
public JmhValueFactory getInstance() {
return new io.usethesource.criterion.impl.persistent.dexx.DexxValueFactory();
}
},
VF_PCOLLECTIONS {
@Override
public JmhValueFactory getInstance() {
return new io.usethesource.criterion.impl.persistent.pcollections.PcollectionsValueFactory();
}
},
VF_GUAVA_IMMUTABLE {
@Override
public JmhValueFactory getInstance() { | // Path: src/main/java/io/usethesource/criterion/api/JmhValueFactory.java
// public interface JmhValueFactory {
//
// static RuntimeException FACTORY_NOT_YET_IMPLEMENTED_EXCEPTION =
// new UnsupportedOperationException("Not yet implemented.");
//
// // default JmhSet set() {
// // return setBuilder().done();
// // }
//
// default JmhSet.Builder setBuilder() {
// throw FACTORY_NOT_YET_IMPLEMENTED_EXCEPTION;
// }
//
// // default JmhMap map() {
// // return mapBuilder().done();
// // }
//
// default JmhMap.Builder mapBuilder() {
// throw FACTORY_NOT_YET_IMPLEMENTED_EXCEPTION;
// }
//
// // default JmhSetMultimap setMulimap() {
// // return setMultimapBuilder().done();
// // }
//
// default JmhSetMultimap.Builder setMultimapBuilder() {
// throw FACTORY_NOT_YET_IMPLEMENTED_EXCEPTION;
// }
//
// }
//
// Path: src/main/java/io/usethesource/criterion/impl/immutable/guava/ImmutableGuavaValueFactory.java
// public class ImmutableGuavaValueFactory implements JmhValueFactory {
//
// public ImmutableGuavaValueFactory() {
// }
//
// @Override
// public JmhSet.Builder setBuilder() {
// return new ImmutableGuavaSetBuilder();
// }
//
// @Override
// public JmhMap.Builder mapBuilder() {
// return new ImmutableGuavaMapBuilder();
// }
//
// @Override
// public JmhSetMultimap.Builder setMultimapBuilder() {
// return new ImmutableGuavaSetMultimapBuilder();
// }
//
// @Override
// public String toString() {
// return "VF_GUAVA_IMMUTABLE";
// }
//
// }
//
// Path: src/main/java/io/usethesource/criterion/impl/persistent/paguro/PaguroValueFactory.java
// public class PaguroValueFactory implements JmhValueFactory {
//
// @Override
// public JmhSet.Builder setBuilder() {
// return new PaguroSetBuilder();
// }
//
// @Override
// public JmhMap.Builder mapBuilder() {
// return new PaguroMapBuilder();
// }
//
// @Override
// public String toString() {
// return "VF_PAGURO";
// }
//
// }
//
// Path: src/main/java/io/usethesource/criterion/impl/persistent/vavr/VavrValueFactory.java
// public class VavrValueFactory implements JmhValueFactory {
//
// @Override
// public JmhSet.Builder setBuilder() {
// return new VavrSetBuilder();
// }
//
// @Override
// public JmhMap.Builder mapBuilder() {
// return new VavrMapBuilder();
// }
//
// @Override
// public String toString() {
// return "VF_VAVR";
// }
//
// }
// Path: src/main/java/io/usethesource/criterion/BenchmarkUtils.java
import java.util.Arrays;
import java.util.Random;
import io.usethesource.capsule.core.PersistentBidirectionalTrieSetMultimap;
import io.usethesource.capsule.core.PersistentTrieMap;
import io.usethesource.capsule.core.PersistentTrieSet;
import io.usethesource.capsule.core.PersistentTrieSetMultimap;
import io.usethesource.capsule.experimental.heterogeneous.TrieMap_5Bits_Heterogeneous_BleedingEdge;
import io.usethesource.capsule.experimental.memoized.TrieMap_5Bits_Memoized_LazyHashCode;
import io.usethesource.capsule.experimental.memoized.TrieSet_5Bits_Memoized_LazyHashCode;
import io.usethesource.capsule.experimental.multimap.TrieSetMultimap_HHAMT;
import io.usethesource.capsule.experimental.multimap.TrieSetMultimap_HHAMT_Specialized;
import io.usethesource.capsule.experimental.specialized.TrieMap_5Bits_Spec0To8;
import io.usethesource.capsule.experimental.specialized.TrieSet_5Bits_Spec0To8;
import io.usethesource.criterion.api.JmhValueFactory;
import io.usethesource.criterion.impl.immutable.guava.ImmutableGuavaValueFactory;
import io.usethesource.criterion.impl.persistent.paguro.PaguroValueFactory;
import io.usethesource.criterion.impl.persistent.vavr.VavrValueFactory;
TrieSet_5Bits_Spec0To8.class, TrieMap_5Bits_Spec0To8.class, null);
}
},
VF_VAVR {
@Override
public JmhValueFactory getInstance() {
return new VavrValueFactory();
}
},
VF_PAGURO {
@Override
public JmhValueFactory getInstance() {
return new PaguroValueFactory();
}
},
VF_DEXX {
@Override
public JmhValueFactory getInstance() {
return new io.usethesource.criterion.impl.persistent.dexx.DexxValueFactory();
}
},
VF_PCOLLECTIONS {
@Override
public JmhValueFactory getInstance() {
return new io.usethesource.criterion.impl.persistent.pcollections.PcollectionsValueFactory();
}
},
VF_GUAVA_IMMUTABLE {
@Override
public JmhValueFactory getInstance() { | return new ImmutableGuavaValueFactory(); |
msteindorfer/criterion | src/main/java/io/usethesource/criterion/impl/persistent/vavr/VavrValueFactory.java | // Path: src/main/java/io/usethesource/criterion/api/JmhMap.java
// public interface JmhMap extends Iterable<JmhValue>, JmhValue {
//
// public boolean isEmpty();
//
// public int size();
//
// public JmhMap put(JmhValue key, JmhValue value);
//
// public JmhMap removeKey(JmhValue key);
//
// /**
// * @return the value that is mapped to this key, or null if no such value exists
// */
// public JmhValue get(JmhValue key);
//
// public boolean containsKey(JmhValue key);
//
// public boolean containsValue(JmhValue value);
//
// /**
// * @return an iterator over the keys of the map
// */
// @Override
// public Iterator<JmhValue> iterator();
//
// /**
// * @return an iterator over the values of the map
// */
// public Iterator<JmhValue> valueIterator();
//
// /**
// * @return an iterator over the keys-value pairs of the map
// */
// public Iterator<Entry<JmhValue, JmhValue>> entryIterator();
//
// public static interface Builder extends JmhBuilder {
//
// void put(JmhValue key, JmhValue value);
//
// void putAll(JmhMap map);
//
// void putAll(Map<JmhValue, JmhValue> map);
//
// @Override
// JmhMap done();
//
// }
//
// }
//
// Path: src/main/java/io/usethesource/criterion/api/JmhSet.java
// public interface JmhSet extends JmhValue, Iterable<JmhValue> {
//
// boolean isEmpty();
//
// int size();
//
// boolean contains(JmhValue element);
//
// JmhSet insert(JmhValue element);
//
// JmhSet delete(JmhValue elem);
//
// default boolean subsetOf(JmhSet other) {
// throw new UnsupportedOperationException();
// }
//
// default JmhSet union(JmhSet other) {
// throw new UnsupportedOperationException();
// }
//
// default JmhSet subtract(JmhSet other) {
// throw new UnsupportedOperationException();
// }
//
// default JmhSet intersect(JmhSet other) {
// throw new UnsupportedOperationException();
// }
//
// @Override
// Iterator<JmhValue> iterator();
//
// @Deprecated
// java.util.Set<JmhValue> asJavaSet();
//
// interface Builder extends JmhBuilder {
//
// @Deprecated
// default void insert(JmhValue value) {
// insert(new JmhValue[]{value});
// }
//
// void insert(JmhValue... v);
//
// void insertAll(Iterable<? extends JmhValue> collection);
//
// @Override
// JmhSet done();
//
// }
//
// }
//
// Path: src/main/java/io/usethesource/criterion/api/JmhValueFactory.java
// public interface JmhValueFactory {
//
// static RuntimeException FACTORY_NOT_YET_IMPLEMENTED_EXCEPTION =
// new UnsupportedOperationException("Not yet implemented.");
//
// // default JmhSet set() {
// // return setBuilder().done();
// // }
//
// default JmhSet.Builder setBuilder() {
// throw FACTORY_NOT_YET_IMPLEMENTED_EXCEPTION;
// }
//
// // default JmhMap map() {
// // return mapBuilder().done();
// // }
//
// default JmhMap.Builder mapBuilder() {
// throw FACTORY_NOT_YET_IMPLEMENTED_EXCEPTION;
// }
//
// // default JmhSetMultimap setMulimap() {
// // return setMultimapBuilder().done();
// // }
//
// default JmhSetMultimap.Builder setMultimapBuilder() {
// throw FACTORY_NOT_YET_IMPLEMENTED_EXCEPTION;
// }
//
// }
| import io.usethesource.criterion.api.JmhMap;
import io.usethesource.criterion.api.JmhSet;
import io.usethesource.criterion.api.JmhValueFactory; | /**
* Copyright (c) Michael Steindorfer <Centrum Wiskunde & Informatica> and Contributors.
* All rights reserved.
*
* This file is licensed under the BSD 2-Clause License, which accompanies this project
* and is available under https://opensource.org/licenses/BSD-2-Clause.
*/
package io.usethesource.criterion.impl.persistent.vavr;
public class VavrValueFactory implements JmhValueFactory {
@Override | // Path: src/main/java/io/usethesource/criterion/api/JmhMap.java
// public interface JmhMap extends Iterable<JmhValue>, JmhValue {
//
// public boolean isEmpty();
//
// public int size();
//
// public JmhMap put(JmhValue key, JmhValue value);
//
// public JmhMap removeKey(JmhValue key);
//
// /**
// * @return the value that is mapped to this key, or null if no such value exists
// */
// public JmhValue get(JmhValue key);
//
// public boolean containsKey(JmhValue key);
//
// public boolean containsValue(JmhValue value);
//
// /**
// * @return an iterator over the keys of the map
// */
// @Override
// public Iterator<JmhValue> iterator();
//
// /**
// * @return an iterator over the values of the map
// */
// public Iterator<JmhValue> valueIterator();
//
// /**
// * @return an iterator over the keys-value pairs of the map
// */
// public Iterator<Entry<JmhValue, JmhValue>> entryIterator();
//
// public static interface Builder extends JmhBuilder {
//
// void put(JmhValue key, JmhValue value);
//
// void putAll(JmhMap map);
//
// void putAll(Map<JmhValue, JmhValue> map);
//
// @Override
// JmhMap done();
//
// }
//
// }
//
// Path: src/main/java/io/usethesource/criterion/api/JmhSet.java
// public interface JmhSet extends JmhValue, Iterable<JmhValue> {
//
// boolean isEmpty();
//
// int size();
//
// boolean contains(JmhValue element);
//
// JmhSet insert(JmhValue element);
//
// JmhSet delete(JmhValue elem);
//
// default boolean subsetOf(JmhSet other) {
// throw new UnsupportedOperationException();
// }
//
// default JmhSet union(JmhSet other) {
// throw new UnsupportedOperationException();
// }
//
// default JmhSet subtract(JmhSet other) {
// throw new UnsupportedOperationException();
// }
//
// default JmhSet intersect(JmhSet other) {
// throw new UnsupportedOperationException();
// }
//
// @Override
// Iterator<JmhValue> iterator();
//
// @Deprecated
// java.util.Set<JmhValue> asJavaSet();
//
// interface Builder extends JmhBuilder {
//
// @Deprecated
// default void insert(JmhValue value) {
// insert(new JmhValue[]{value});
// }
//
// void insert(JmhValue... v);
//
// void insertAll(Iterable<? extends JmhValue> collection);
//
// @Override
// JmhSet done();
//
// }
//
// }
//
// Path: src/main/java/io/usethesource/criterion/api/JmhValueFactory.java
// public interface JmhValueFactory {
//
// static RuntimeException FACTORY_NOT_YET_IMPLEMENTED_EXCEPTION =
// new UnsupportedOperationException("Not yet implemented.");
//
// // default JmhSet set() {
// // return setBuilder().done();
// // }
//
// default JmhSet.Builder setBuilder() {
// throw FACTORY_NOT_YET_IMPLEMENTED_EXCEPTION;
// }
//
// // default JmhMap map() {
// // return mapBuilder().done();
// // }
//
// default JmhMap.Builder mapBuilder() {
// throw FACTORY_NOT_YET_IMPLEMENTED_EXCEPTION;
// }
//
// // default JmhSetMultimap setMulimap() {
// // return setMultimapBuilder().done();
// // }
//
// default JmhSetMultimap.Builder setMultimapBuilder() {
// throw FACTORY_NOT_YET_IMPLEMENTED_EXCEPTION;
// }
//
// }
// Path: src/main/java/io/usethesource/criterion/impl/persistent/vavr/VavrValueFactory.java
import io.usethesource.criterion.api.JmhMap;
import io.usethesource.criterion.api.JmhSet;
import io.usethesource.criterion.api.JmhValueFactory;
/**
* Copyright (c) Michael Steindorfer <Centrum Wiskunde & Informatica> and Contributors.
* All rights reserved.
*
* This file is licensed under the BSD 2-Clause License, which accompanies this project
* and is available under https://opensource.org/licenses/BSD-2-Clause.
*/
package io.usethesource.criterion.impl.persistent.vavr;
public class VavrValueFactory implements JmhValueFactory {
@Override | public JmhSet.Builder setBuilder() { |
msteindorfer/criterion | src/main/java/io/usethesource/criterion/impl/persistent/vavr/VavrValueFactory.java | // Path: src/main/java/io/usethesource/criterion/api/JmhMap.java
// public interface JmhMap extends Iterable<JmhValue>, JmhValue {
//
// public boolean isEmpty();
//
// public int size();
//
// public JmhMap put(JmhValue key, JmhValue value);
//
// public JmhMap removeKey(JmhValue key);
//
// /**
// * @return the value that is mapped to this key, or null if no such value exists
// */
// public JmhValue get(JmhValue key);
//
// public boolean containsKey(JmhValue key);
//
// public boolean containsValue(JmhValue value);
//
// /**
// * @return an iterator over the keys of the map
// */
// @Override
// public Iterator<JmhValue> iterator();
//
// /**
// * @return an iterator over the values of the map
// */
// public Iterator<JmhValue> valueIterator();
//
// /**
// * @return an iterator over the keys-value pairs of the map
// */
// public Iterator<Entry<JmhValue, JmhValue>> entryIterator();
//
// public static interface Builder extends JmhBuilder {
//
// void put(JmhValue key, JmhValue value);
//
// void putAll(JmhMap map);
//
// void putAll(Map<JmhValue, JmhValue> map);
//
// @Override
// JmhMap done();
//
// }
//
// }
//
// Path: src/main/java/io/usethesource/criterion/api/JmhSet.java
// public interface JmhSet extends JmhValue, Iterable<JmhValue> {
//
// boolean isEmpty();
//
// int size();
//
// boolean contains(JmhValue element);
//
// JmhSet insert(JmhValue element);
//
// JmhSet delete(JmhValue elem);
//
// default boolean subsetOf(JmhSet other) {
// throw new UnsupportedOperationException();
// }
//
// default JmhSet union(JmhSet other) {
// throw new UnsupportedOperationException();
// }
//
// default JmhSet subtract(JmhSet other) {
// throw new UnsupportedOperationException();
// }
//
// default JmhSet intersect(JmhSet other) {
// throw new UnsupportedOperationException();
// }
//
// @Override
// Iterator<JmhValue> iterator();
//
// @Deprecated
// java.util.Set<JmhValue> asJavaSet();
//
// interface Builder extends JmhBuilder {
//
// @Deprecated
// default void insert(JmhValue value) {
// insert(new JmhValue[]{value});
// }
//
// void insert(JmhValue... v);
//
// void insertAll(Iterable<? extends JmhValue> collection);
//
// @Override
// JmhSet done();
//
// }
//
// }
//
// Path: src/main/java/io/usethesource/criterion/api/JmhValueFactory.java
// public interface JmhValueFactory {
//
// static RuntimeException FACTORY_NOT_YET_IMPLEMENTED_EXCEPTION =
// new UnsupportedOperationException("Not yet implemented.");
//
// // default JmhSet set() {
// // return setBuilder().done();
// // }
//
// default JmhSet.Builder setBuilder() {
// throw FACTORY_NOT_YET_IMPLEMENTED_EXCEPTION;
// }
//
// // default JmhMap map() {
// // return mapBuilder().done();
// // }
//
// default JmhMap.Builder mapBuilder() {
// throw FACTORY_NOT_YET_IMPLEMENTED_EXCEPTION;
// }
//
// // default JmhSetMultimap setMulimap() {
// // return setMultimapBuilder().done();
// // }
//
// default JmhSetMultimap.Builder setMultimapBuilder() {
// throw FACTORY_NOT_YET_IMPLEMENTED_EXCEPTION;
// }
//
// }
| import io.usethesource.criterion.api.JmhMap;
import io.usethesource.criterion.api.JmhSet;
import io.usethesource.criterion.api.JmhValueFactory; | /**
* Copyright (c) Michael Steindorfer <Centrum Wiskunde & Informatica> and Contributors.
* All rights reserved.
*
* This file is licensed under the BSD 2-Clause License, which accompanies this project
* and is available under https://opensource.org/licenses/BSD-2-Clause.
*/
package io.usethesource.criterion.impl.persistent.vavr;
public class VavrValueFactory implements JmhValueFactory {
@Override
public JmhSet.Builder setBuilder() {
return new VavrSetBuilder();
}
@Override | // Path: src/main/java/io/usethesource/criterion/api/JmhMap.java
// public interface JmhMap extends Iterable<JmhValue>, JmhValue {
//
// public boolean isEmpty();
//
// public int size();
//
// public JmhMap put(JmhValue key, JmhValue value);
//
// public JmhMap removeKey(JmhValue key);
//
// /**
// * @return the value that is mapped to this key, or null if no such value exists
// */
// public JmhValue get(JmhValue key);
//
// public boolean containsKey(JmhValue key);
//
// public boolean containsValue(JmhValue value);
//
// /**
// * @return an iterator over the keys of the map
// */
// @Override
// public Iterator<JmhValue> iterator();
//
// /**
// * @return an iterator over the values of the map
// */
// public Iterator<JmhValue> valueIterator();
//
// /**
// * @return an iterator over the keys-value pairs of the map
// */
// public Iterator<Entry<JmhValue, JmhValue>> entryIterator();
//
// public static interface Builder extends JmhBuilder {
//
// void put(JmhValue key, JmhValue value);
//
// void putAll(JmhMap map);
//
// void putAll(Map<JmhValue, JmhValue> map);
//
// @Override
// JmhMap done();
//
// }
//
// }
//
// Path: src/main/java/io/usethesource/criterion/api/JmhSet.java
// public interface JmhSet extends JmhValue, Iterable<JmhValue> {
//
// boolean isEmpty();
//
// int size();
//
// boolean contains(JmhValue element);
//
// JmhSet insert(JmhValue element);
//
// JmhSet delete(JmhValue elem);
//
// default boolean subsetOf(JmhSet other) {
// throw new UnsupportedOperationException();
// }
//
// default JmhSet union(JmhSet other) {
// throw new UnsupportedOperationException();
// }
//
// default JmhSet subtract(JmhSet other) {
// throw new UnsupportedOperationException();
// }
//
// default JmhSet intersect(JmhSet other) {
// throw new UnsupportedOperationException();
// }
//
// @Override
// Iterator<JmhValue> iterator();
//
// @Deprecated
// java.util.Set<JmhValue> asJavaSet();
//
// interface Builder extends JmhBuilder {
//
// @Deprecated
// default void insert(JmhValue value) {
// insert(new JmhValue[]{value});
// }
//
// void insert(JmhValue... v);
//
// void insertAll(Iterable<? extends JmhValue> collection);
//
// @Override
// JmhSet done();
//
// }
//
// }
//
// Path: src/main/java/io/usethesource/criterion/api/JmhValueFactory.java
// public interface JmhValueFactory {
//
// static RuntimeException FACTORY_NOT_YET_IMPLEMENTED_EXCEPTION =
// new UnsupportedOperationException("Not yet implemented.");
//
// // default JmhSet set() {
// // return setBuilder().done();
// // }
//
// default JmhSet.Builder setBuilder() {
// throw FACTORY_NOT_YET_IMPLEMENTED_EXCEPTION;
// }
//
// // default JmhMap map() {
// // return mapBuilder().done();
// // }
//
// default JmhMap.Builder mapBuilder() {
// throw FACTORY_NOT_YET_IMPLEMENTED_EXCEPTION;
// }
//
// // default JmhSetMultimap setMulimap() {
// // return setMultimapBuilder().done();
// // }
//
// default JmhSetMultimap.Builder setMultimapBuilder() {
// throw FACTORY_NOT_YET_IMPLEMENTED_EXCEPTION;
// }
//
// }
// Path: src/main/java/io/usethesource/criterion/impl/persistent/vavr/VavrValueFactory.java
import io.usethesource.criterion.api.JmhMap;
import io.usethesource.criterion.api.JmhSet;
import io.usethesource.criterion.api.JmhValueFactory;
/**
* Copyright (c) Michael Steindorfer <Centrum Wiskunde & Informatica> and Contributors.
* All rights reserved.
*
* This file is licensed under the BSD 2-Clause License, which accompanies this project
* and is available under https://opensource.org/licenses/BSD-2-Clause.
*/
package io.usethesource.criterion.impl.persistent.vavr;
public class VavrValueFactory implements JmhValueFactory {
@Override
public JmhSet.Builder setBuilder() {
return new VavrSetBuilder();
}
@Override | public JmhMap.Builder mapBuilder() { |
msteindorfer/criterion | src/main/java/io/usethesource/criterion/generators/JmhIntegerGenerator.java | // Path: src/main/java/io/usethesource/criterion/PureInteger.java
// @CompilerControl(Mode.DONT_INLINE)
// public class PureInteger implements JmhValue {
//
// private int value;
//
// public PureInteger(int value) {
// this.value = value;
// }
//
// @Override
// public int hashCode() {
// return value;
// }
//
// @Override
// public boolean equals(Object other) {
// if (other == null) {
// return false;
// }
// if (other == this) {
// return true;
// }
//
// if (other instanceof PureInteger) {
// int otherValue = ((PureInteger) other).value;
//
// return value == otherValue;
// }
// return false;
// }
//
// @Override
// public Object unwrap() {
// return this; // cannot be unwrapped
// }
//
// @Override
// public String toString() {
// return String.valueOf(value);
// }
//
// }
//
// Path: src/main/java/io/usethesource/criterion/api/JmhValue.java
// @CompilerControl(Mode.DONT_INLINE)
// public interface JmhValue {
//
// /**
// * Removes the JmhValue delegation object to reveal its internal representation.
// *
// * @return internal representation
// */
// Object unwrap();
//
// }
| import com.pholser.junit.quickcheck.generator.GenerationStatus;
import com.pholser.junit.quickcheck.generator.Generator;
import com.pholser.junit.quickcheck.random.SourceOfRandomness;
import io.usethesource.criterion.PureInteger;
import io.usethesource.criterion.api.JmhValue; | /**
* Copyright (c) Michael Steindorfer <Centrum Wiskunde & Informatica> and Contributors.
* All rights reserved.
*
* This file is licensed under the BSD 2-Clause License, which accompanies this project
* and is available under https://opensource.org/licenses/BSD-2-Clause.
*/
package io.usethesource.criterion.generators;
public class JmhIntegerGenerator extends Generator<JmhValue> {
public JmhIntegerGenerator() {
super(JmhValue.class);
}
@Override
public JmhValue generate(SourceOfRandomness random, GenerationStatus status) { | // Path: src/main/java/io/usethesource/criterion/PureInteger.java
// @CompilerControl(Mode.DONT_INLINE)
// public class PureInteger implements JmhValue {
//
// private int value;
//
// public PureInteger(int value) {
// this.value = value;
// }
//
// @Override
// public int hashCode() {
// return value;
// }
//
// @Override
// public boolean equals(Object other) {
// if (other == null) {
// return false;
// }
// if (other == this) {
// return true;
// }
//
// if (other instanceof PureInteger) {
// int otherValue = ((PureInteger) other).value;
//
// return value == otherValue;
// }
// return false;
// }
//
// @Override
// public Object unwrap() {
// return this; // cannot be unwrapped
// }
//
// @Override
// public String toString() {
// return String.valueOf(value);
// }
//
// }
//
// Path: src/main/java/io/usethesource/criterion/api/JmhValue.java
// @CompilerControl(Mode.DONT_INLINE)
// public interface JmhValue {
//
// /**
// * Removes the JmhValue delegation object to reveal its internal representation.
// *
// * @return internal representation
// */
// Object unwrap();
//
// }
// Path: src/main/java/io/usethesource/criterion/generators/JmhIntegerGenerator.java
import com.pholser.junit.quickcheck.generator.GenerationStatus;
import com.pholser.junit.quickcheck.generator.Generator;
import com.pholser.junit.quickcheck.random.SourceOfRandomness;
import io.usethesource.criterion.PureInteger;
import io.usethesource.criterion.api.JmhValue;
/**
* Copyright (c) Michael Steindorfer <Centrum Wiskunde & Informatica> and Contributors.
* All rights reserved.
*
* This file is licensed under the BSD 2-Clause License, which accompanies this project
* and is available under https://opensource.org/licenses/BSD-2-Clause.
*/
package io.usethesource.criterion.generators;
public class JmhIntegerGenerator extends Generator<JmhValue> {
public JmhIntegerGenerator() {
super(JmhValue.class);
}
@Override
public JmhValue generate(SourceOfRandomness random, GenerationStatus status) { | return new PureInteger(random.nextInt()); |
msteindorfer/criterion | src/main/java/io/usethesource/criterion/JmhCapsuleSetBenchmark.java | // Path: src/main/java/io/usethesource/criterion/api/JmhValue.java
// @CompilerControl(Mode.DONT_INLINE)
// public interface JmhValue {
//
// /**
// * Removes the JmhValue delegation object to reveal its internal representation.
// *
// * @return internal representation
// */
// Object unwrap();
//
// }
//
// Path: src/main/java/io/usethesource/criterion/generators/JmhSleepingIntegerGenerator.java
// public class JmhSleepingIntegerGenerator extends Generator<JmhValue> {
//
// public JmhSleepingIntegerGenerator() {
// super(JmhValue.class);
// }
//
// @Override
// public JmhValue generate(SourceOfRandomness random, GenerationStatus status) {
// return new SleepingInteger(random.nextInt());
// }
//
// }
//
// Path: src/main/java/io/usethesource/criterion/BenchmarkUtils.java
// public static int seedFromSizeAndRun(int size, int run) {
// return mix(size) ^ mix(run);
// }
| import java.util.Arrays;
import java.util.Random;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.function.Supplier;
import com.pholser.junit.quickcheck.generator.GenerationStatus;
import com.pholser.junit.quickcheck.generator.Generator;
import com.pholser.junit.quickcheck.internal.GeometricDistribution;
import com.pholser.junit.quickcheck.internal.generator.SimpleGenerationStatus;
import com.pholser.junit.quickcheck.random.SourceOfRandomness;
import io.usethesource.capsule.Set;
import io.usethesource.capsule.generators.set.AbstractSetGenerator;
import io.usethesource.capsule.generators.set.SetGeneratorDefault;
import io.usethesource.capsule.generators.set.SetGeneratorMemoizedLazyHashCode;
import io.usethesource.capsule.generators.set.SetGeneratorSpec0To8;
import io.usethesource.criterion.api.JmhValue;
import io.usethesource.criterion.generators.JmhSleepingIntegerGenerator;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.infra.Blackhole;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openjdk.jmh.runner.options.TimeValue;
import static io.usethesource.criterion.BenchmarkUtils.seedFromSizeAndRun; |
@Param({"CHAMP", "MEMCHAMP"})
protected SetGeneratorClassEnum generatorDescriptor;
// static final Class<? extends Set.Immutable> classUnderTest =
// TrieSet_5Bits_Memoized_LazyHashCode.class;
//
// @Param({SetGeneratorMemoizedLazyHashCode.class})
//
// static final Class<?> generatorClass = SetGeneratorMemoizedLazyHashCode.class;
// RuntimeCodeGenerationTestSuite.generatorClass(classUnderTest, JmhValue.class);
/*
* val l = (for (i <- 0 to 23) yield s"'${Math.pow(2, i).toInt}'") val r = (for (i <- 0 to 23)
* yield s"'${Math.pow(2, i-1).toInt + Math.pow(2, i).toInt}'") val zipped = l zip r flatMap {
* case (x,y) => List(x,y) }
*
* val all = zipped.drop(1).take(zipped.size - 2) all.mkString(", ").replace("'", "\"")
*/
@Param({"1", "2", "3", "4", "6", "8", "12", "16", "24", "32", "48", "64", "96", "128", "192",
"256", "384", "512", "768", "1024", "1536", "2048", "3072", "4096", "6144", "8192", "12288",
"16384", "24576", "32768", "49152", "65536", "98304", "131072", "196608", "262144", "393216",
"524288", "786432", "1048576", "1572864", "2097152", "3145728", "4194304", "6291456",
"8388608"})
protected int size;
@Param({"0"}) // "1", "2", "3", "4", "5", "6", "7", "8", "9"
protected int run;
| // Path: src/main/java/io/usethesource/criterion/api/JmhValue.java
// @CompilerControl(Mode.DONT_INLINE)
// public interface JmhValue {
//
// /**
// * Removes the JmhValue delegation object to reveal its internal representation.
// *
// * @return internal representation
// */
// Object unwrap();
//
// }
//
// Path: src/main/java/io/usethesource/criterion/generators/JmhSleepingIntegerGenerator.java
// public class JmhSleepingIntegerGenerator extends Generator<JmhValue> {
//
// public JmhSleepingIntegerGenerator() {
// super(JmhValue.class);
// }
//
// @Override
// public JmhValue generate(SourceOfRandomness random, GenerationStatus status) {
// return new SleepingInteger(random.nextInt());
// }
//
// }
//
// Path: src/main/java/io/usethesource/criterion/BenchmarkUtils.java
// public static int seedFromSizeAndRun(int size, int run) {
// return mix(size) ^ mix(run);
// }
// Path: src/main/java/io/usethesource/criterion/JmhCapsuleSetBenchmark.java
import java.util.Arrays;
import java.util.Random;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.function.Supplier;
import com.pholser.junit.quickcheck.generator.GenerationStatus;
import com.pholser.junit.quickcheck.generator.Generator;
import com.pholser.junit.quickcheck.internal.GeometricDistribution;
import com.pholser.junit.quickcheck.internal.generator.SimpleGenerationStatus;
import com.pholser.junit.quickcheck.random.SourceOfRandomness;
import io.usethesource.capsule.Set;
import io.usethesource.capsule.generators.set.AbstractSetGenerator;
import io.usethesource.capsule.generators.set.SetGeneratorDefault;
import io.usethesource.capsule.generators.set.SetGeneratorMemoizedLazyHashCode;
import io.usethesource.capsule.generators.set.SetGeneratorSpec0To8;
import io.usethesource.criterion.api.JmhValue;
import io.usethesource.criterion.generators.JmhSleepingIntegerGenerator;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.infra.Blackhole;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openjdk.jmh.runner.options.TimeValue;
import static io.usethesource.criterion.BenchmarkUtils.seedFromSizeAndRun;
@Param({"CHAMP", "MEMCHAMP"})
protected SetGeneratorClassEnum generatorDescriptor;
// static final Class<? extends Set.Immutable> classUnderTest =
// TrieSet_5Bits_Memoized_LazyHashCode.class;
//
// @Param({SetGeneratorMemoizedLazyHashCode.class})
//
// static final Class<?> generatorClass = SetGeneratorMemoizedLazyHashCode.class;
// RuntimeCodeGenerationTestSuite.generatorClass(classUnderTest, JmhValue.class);
/*
* val l = (for (i <- 0 to 23) yield s"'${Math.pow(2, i).toInt}'") val r = (for (i <- 0 to 23)
* yield s"'${Math.pow(2, i-1).toInt + Math.pow(2, i).toInt}'") val zipped = l zip r flatMap {
* case (x,y) => List(x,y) }
*
* val all = zipped.drop(1).take(zipped.size - 2) all.mkString(", ").replace("'", "\"")
*/
@Param({"1", "2", "3", "4", "6", "8", "12", "16", "24", "32", "48", "64", "96", "128", "192",
"256", "384", "512", "768", "1024", "1536", "2048", "3072", "4096", "6144", "8192", "12288",
"16384", "24576", "32768", "49152", "65536", "98304", "131072", "196608", "262144", "393216",
"524288", "786432", "1048576", "1572864", "2097152", "3145728", "4194304", "6291456",
"8388608"})
protected int size;
@Param({"0"}) // "1", "2", "3", "4", "5", "6", "7", "8", "9"
protected int run;
| private Set.Immutable<JmhValue> testSet1; |
msteindorfer/criterion | src/main/java/io/usethesource/criterion/JmhCapsuleSetBenchmark.java | // Path: src/main/java/io/usethesource/criterion/api/JmhValue.java
// @CompilerControl(Mode.DONT_INLINE)
// public interface JmhValue {
//
// /**
// * Removes the JmhValue delegation object to reveal its internal representation.
// *
// * @return internal representation
// */
// Object unwrap();
//
// }
//
// Path: src/main/java/io/usethesource/criterion/generators/JmhSleepingIntegerGenerator.java
// public class JmhSleepingIntegerGenerator extends Generator<JmhValue> {
//
// public JmhSleepingIntegerGenerator() {
// super(JmhValue.class);
// }
//
// @Override
// public JmhValue generate(SourceOfRandomness random, GenerationStatus status) {
// return new SleepingInteger(random.nextInt());
// }
//
// }
//
// Path: src/main/java/io/usethesource/criterion/BenchmarkUtils.java
// public static int seedFromSizeAndRun(int size, int run) {
// return mix(size) ^ mix(run);
// }
| import java.util.Arrays;
import java.util.Random;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.function.Supplier;
import com.pholser.junit.quickcheck.generator.GenerationStatus;
import com.pholser.junit.quickcheck.generator.Generator;
import com.pholser.junit.quickcheck.internal.GeometricDistribution;
import com.pholser.junit.quickcheck.internal.generator.SimpleGenerationStatus;
import com.pholser.junit.quickcheck.random.SourceOfRandomness;
import io.usethesource.capsule.Set;
import io.usethesource.capsule.generators.set.AbstractSetGenerator;
import io.usethesource.capsule.generators.set.SetGeneratorDefault;
import io.usethesource.capsule.generators.set.SetGeneratorMemoizedLazyHashCode;
import io.usethesource.capsule.generators.set.SetGeneratorSpec0To8;
import io.usethesource.criterion.api.JmhValue;
import io.usethesource.criterion.generators.JmhSleepingIntegerGenerator;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.infra.Blackhole;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openjdk.jmh.runner.options.TimeValue;
import static io.usethesource.criterion.BenchmarkUtils.seedFromSizeAndRun; |
@Param({"0"}) // "1", "2", "3", "4", "5", "6", "7", "8", "9"
protected int run;
private Set.Immutable<JmhValue> testSet1;
private Set.Immutable<JmhValue> testSet2;
private Set.Immutable<JmhValue> testSetCommon;
private Set.Immutable<JmhValue> testSet1Duplicate;
private Set.Immutable<JmhValue> testSet2Duplicate;
public JmhValue VALUE_EXISTING;
public JmhValue VALUE_NOT_EXISTING;
public static final int CACHED_NUMBERS_SIZE = 8;
public JmhValue[] cachedNumbers = new JmhValue[CACHED_NUMBERS_SIZE];
public JmhValue[] cachedNumbersNotContained = new JmhValue[CACHED_NUMBERS_SIZE];
public static final Class<JmhValue> payloadToken = JmhValue.class;
@Setup(Level.Trial)
public void setUp() throws Exception {
final Generator<JmhValue> itemGenerator;
final AbstractSetGenerator<? extends Set.Immutable> collectionGenerator;
final SourceOfRandomness random0 = new SourceOfRandomness(new Random(13));
final GenerationStatus status0 = freshGenerationStatus.apply(random0);
try { | // Path: src/main/java/io/usethesource/criterion/api/JmhValue.java
// @CompilerControl(Mode.DONT_INLINE)
// public interface JmhValue {
//
// /**
// * Removes the JmhValue delegation object to reveal its internal representation.
// *
// * @return internal representation
// */
// Object unwrap();
//
// }
//
// Path: src/main/java/io/usethesource/criterion/generators/JmhSleepingIntegerGenerator.java
// public class JmhSleepingIntegerGenerator extends Generator<JmhValue> {
//
// public JmhSleepingIntegerGenerator() {
// super(JmhValue.class);
// }
//
// @Override
// public JmhValue generate(SourceOfRandomness random, GenerationStatus status) {
// return new SleepingInteger(random.nextInt());
// }
//
// }
//
// Path: src/main/java/io/usethesource/criterion/BenchmarkUtils.java
// public static int seedFromSizeAndRun(int size, int run) {
// return mix(size) ^ mix(run);
// }
// Path: src/main/java/io/usethesource/criterion/JmhCapsuleSetBenchmark.java
import java.util.Arrays;
import java.util.Random;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.function.Supplier;
import com.pholser.junit.quickcheck.generator.GenerationStatus;
import com.pholser.junit.quickcheck.generator.Generator;
import com.pholser.junit.quickcheck.internal.GeometricDistribution;
import com.pholser.junit.quickcheck.internal.generator.SimpleGenerationStatus;
import com.pholser.junit.quickcheck.random.SourceOfRandomness;
import io.usethesource.capsule.Set;
import io.usethesource.capsule.generators.set.AbstractSetGenerator;
import io.usethesource.capsule.generators.set.SetGeneratorDefault;
import io.usethesource.capsule.generators.set.SetGeneratorMemoizedLazyHashCode;
import io.usethesource.capsule.generators.set.SetGeneratorSpec0To8;
import io.usethesource.criterion.api.JmhValue;
import io.usethesource.criterion.generators.JmhSleepingIntegerGenerator;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.infra.Blackhole;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openjdk.jmh.runner.options.TimeValue;
import static io.usethesource.criterion.BenchmarkUtils.seedFromSizeAndRun;
@Param({"0"}) // "1", "2", "3", "4", "5", "6", "7", "8", "9"
protected int run;
private Set.Immutable<JmhValue> testSet1;
private Set.Immutable<JmhValue> testSet2;
private Set.Immutable<JmhValue> testSetCommon;
private Set.Immutable<JmhValue> testSet1Duplicate;
private Set.Immutable<JmhValue> testSet2Duplicate;
public JmhValue VALUE_EXISTING;
public JmhValue VALUE_NOT_EXISTING;
public static final int CACHED_NUMBERS_SIZE = 8;
public JmhValue[] cachedNumbers = new JmhValue[CACHED_NUMBERS_SIZE];
public JmhValue[] cachedNumbersNotContained = new JmhValue[CACHED_NUMBERS_SIZE];
public static final Class<JmhValue> payloadToken = JmhValue.class;
@Setup(Level.Trial)
public void setUp() throws Exception {
final Generator<JmhValue> itemGenerator;
final AbstractSetGenerator<? extends Set.Immutable> collectionGenerator;
final SourceOfRandomness random0 = new SourceOfRandomness(new Random(13));
final GenerationStatus status0 = freshGenerationStatus.apply(random0);
try { | itemGenerator = new JmhSleepingIntegerGenerator(); |
msteindorfer/criterion | src/main/java/io/usethesource/criterion/JmhCapsuleSetBenchmark.java | // Path: src/main/java/io/usethesource/criterion/api/JmhValue.java
// @CompilerControl(Mode.DONT_INLINE)
// public interface JmhValue {
//
// /**
// * Removes the JmhValue delegation object to reveal its internal representation.
// *
// * @return internal representation
// */
// Object unwrap();
//
// }
//
// Path: src/main/java/io/usethesource/criterion/generators/JmhSleepingIntegerGenerator.java
// public class JmhSleepingIntegerGenerator extends Generator<JmhValue> {
//
// public JmhSleepingIntegerGenerator() {
// super(JmhValue.class);
// }
//
// @Override
// public JmhValue generate(SourceOfRandomness random, GenerationStatus status) {
// return new SleepingInteger(random.nextInt());
// }
//
// }
//
// Path: src/main/java/io/usethesource/criterion/BenchmarkUtils.java
// public static int seedFromSizeAndRun(int size, int run) {
// return mix(size) ^ mix(run);
// }
| import java.util.Arrays;
import java.util.Random;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.function.Supplier;
import com.pholser.junit.quickcheck.generator.GenerationStatus;
import com.pholser.junit.quickcheck.generator.Generator;
import com.pholser.junit.quickcheck.internal.GeometricDistribution;
import com.pholser.junit.quickcheck.internal.generator.SimpleGenerationStatus;
import com.pholser.junit.quickcheck.random.SourceOfRandomness;
import io.usethesource.capsule.Set;
import io.usethesource.capsule.generators.set.AbstractSetGenerator;
import io.usethesource.capsule.generators.set.SetGeneratorDefault;
import io.usethesource.capsule.generators.set.SetGeneratorMemoizedLazyHashCode;
import io.usethesource.capsule.generators.set.SetGeneratorSpec0To8;
import io.usethesource.criterion.api.JmhValue;
import io.usethesource.criterion.generators.JmhSleepingIntegerGenerator;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.infra.Blackhole;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openjdk.jmh.runner.options.TimeValue;
import static io.usethesource.criterion.BenchmarkUtils.seedFromSizeAndRun; | // assert Stream.of(cachedNumbers)
// .allMatch(sample -> testSet1.contains(Triple.of(sample, sample, sample)));
//
// /*
// * generate random integers that are not yet contained in the data set
// */
// for (int i = 0; i < CACHED_NUMBERS_SIZE; i++) {
// boolean found = false;
// while (!found) {
// final JmhValue candidate = itemGenerator.generate(random, status);
//
// if (!elements.contains(candidate)) {
// cachedNumbersNotContained[i] = candidate;
// found = true;
// }
// }
// }
//
// // assert (contained)
// assert Stream.of(cachedNumbersNotContained)
// .noneMatch(sample -> testSet1.contains(Triple.of(sample, sample, sample)));
//
// VALUE_EXISTING = cachedNumbers[0];
// VALUE_NOT_EXISTING = cachedNumbersNotContained[0];
// VALUE_EXISTING = cachedNumbers[0];
VALUE_NOT_EXISTING = itemGenerator.generate(random0, status0);
}
private final Supplier<SourceOfRandomness> freshRandom = () -> new SourceOfRandomness( | // Path: src/main/java/io/usethesource/criterion/api/JmhValue.java
// @CompilerControl(Mode.DONT_INLINE)
// public interface JmhValue {
//
// /**
// * Removes the JmhValue delegation object to reveal its internal representation.
// *
// * @return internal representation
// */
// Object unwrap();
//
// }
//
// Path: src/main/java/io/usethesource/criterion/generators/JmhSleepingIntegerGenerator.java
// public class JmhSleepingIntegerGenerator extends Generator<JmhValue> {
//
// public JmhSleepingIntegerGenerator() {
// super(JmhValue.class);
// }
//
// @Override
// public JmhValue generate(SourceOfRandomness random, GenerationStatus status) {
// return new SleepingInteger(random.nextInt());
// }
//
// }
//
// Path: src/main/java/io/usethesource/criterion/BenchmarkUtils.java
// public static int seedFromSizeAndRun(int size, int run) {
// return mix(size) ^ mix(run);
// }
// Path: src/main/java/io/usethesource/criterion/JmhCapsuleSetBenchmark.java
import java.util.Arrays;
import java.util.Random;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.function.Supplier;
import com.pholser.junit.quickcheck.generator.GenerationStatus;
import com.pholser.junit.quickcheck.generator.Generator;
import com.pholser.junit.quickcheck.internal.GeometricDistribution;
import com.pholser.junit.quickcheck.internal.generator.SimpleGenerationStatus;
import com.pholser.junit.quickcheck.random.SourceOfRandomness;
import io.usethesource.capsule.Set;
import io.usethesource.capsule.generators.set.AbstractSetGenerator;
import io.usethesource.capsule.generators.set.SetGeneratorDefault;
import io.usethesource.capsule.generators.set.SetGeneratorMemoizedLazyHashCode;
import io.usethesource.capsule.generators.set.SetGeneratorSpec0To8;
import io.usethesource.criterion.api.JmhValue;
import io.usethesource.criterion.generators.JmhSleepingIntegerGenerator;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.infra.Blackhole;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openjdk.jmh.runner.options.TimeValue;
import static io.usethesource.criterion.BenchmarkUtils.seedFromSizeAndRun;
// assert Stream.of(cachedNumbers)
// .allMatch(sample -> testSet1.contains(Triple.of(sample, sample, sample)));
//
// /*
// * generate random integers that are not yet contained in the data set
// */
// for (int i = 0; i < CACHED_NUMBERS_SIZE; i++) {
// boolean found = false;
// while (!found) {
// final JmhValue candidate = itemGenerator.generate(random, status);
//
// if (!elements.contains(candidate)) {
// cachedNumbersNotContained[i] = candidate;
// found = true;
// }
// }
// }
//
// // assert (contained)
// assert Stream.of(cachedNumbersNotContained)
// .noneMatch(sample -> testSet1.contains(Triple.of(sample, sample, sample)));
//
// VALUE_EXISTING = cachedNumbers[0];
// VALUE_NOT_EXISTING = cachedNumbersNotContained[0];
// VALUE_EXISTING = cachedNumbers[0];
VALUE_NOT_EXISTING = itemGenerator.generate(random0, status0);
}
private final Supplier<SourceOfRandomness> freshRandom = () -> new SourceOfRandomness( | new Random(seedFromSizeAndRun(size, run))); |
msteindorfer/criterion | src/main/java/dom/DominatorsPDB.java | // Path: src/main/java/org/rascalmpl/interpreter/utils/Timing.java
// public final class Timing {
//
// private long start;
//
// public Timing() {
// super();
// }
//
// public void start() {
// start = getCpuTime();
// }
//
// public long duration() {
// long now = getCpuTime();
// long diff = now - start;
// start = now;
// return diff;
// }
//
// public static long getCpuTime() {
// ThreadMXBean bean = ManagementFactory.getThreadMXBean();
// return bean.isCurrentThreadCpuTimeSupported() ?
// bean.getCurrentThreadCpuTime() : 0L;
// }
//
// /**
// * Get user time in nanoseconds.
// */
// public static long getUserTime() {
// ThreadMXBean bean = ManagementFactory.getThreadMXBean();
// return bean.isCurrentThreadCpuTimeSupported() ?
// bean.getCurrentThreadUserTime() : 0L;
// }
//
// /**
// * Get system time in nanoseconds.
// */
// public static long getSystemTime() {
// ThreadMXBean bean = ManagementFactory.getThreadMXBean();
// return bean.isCurrentThreadCpuTimeSupported() ?
// (bean.getCurrentThreadCpuTime() - bean.getCurrentThreadUserTime()) : 0L;
// }
// }
//
// Path: src/main/java/dom/AllDominatorsRunner.java
// public static final String DATA_SET_SINGLE_FILE_NAME = "data/single.bin";
//
// Path: src/main/java/dom/AllDominatorsRunner.java
// public static final boolean LOG_BINARY_RESULTS = false;
//
// Path: src/main/java/dom/AllDominatorsRunner.java
// public static final boolean LOG_TEXTUAL_RESULTS = false;
| import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import io.usethesource.capsule.Set;
import io.usethesource.capsule.Set.Transient;
import io.usethesource.vallang.IConstructor;
import io.usethesource.vallang.IMap;
import io.usethesource.vallang.IMapWriter;
import io.usethesource.vallang.ISet;
import io.usethesource.vallang.ISetWriter;
import io.usethesource.vallang.ITuple;
import io.usethesource.vallang.IValue;
import io.usethesource.vallang.IValueFactory;
import io.usethesource.vallang.io.StandardTextWriter;
import io.usethesource.vallang.io.old.BinaryValueReader;
import io.usethesource.vallang.io.old.BinaryValueWriter;
import org.rascalmpl.interpreter.utils.Timing;
import static dom.AllDominatorsRunner.CURRENT_DATA_SET_FILE_NAME;
import static dom.AllDominatorsRunner.DATA_SET_SINGLE_FILE_NAME;
import static dom.AllDominatorsRunner.LOG_BINARY_RESULTS;
import static dom.AllDominatorsRunner.LOG_TEXTUAL_RESULTS; | // throw new RuntimeException("not the right type: " + sos.getType());
// }
ISet intersected = intersect(sos);
// if (!intersected.getType().isSet() ||
// !intersected.getType().getElementType().isAbstractData()) {
// throw new RuntimeException("not the right type: " + intersected.getType());
// }
ISet newValue = vf.set(n).union(intersected);
// if (!newValue.getElementType().isAbstractData()) {
// System.err.println("problem");
// }
newDom.put(n, newValue);
}
// if (!newDom.done().getValueType().getElementType().isAbstractData()) {
// System.err.println("not good");
// }
dom = newDom.done();
}
return dom;
}
public static void main(String[] args) throws FileNotFoundException, IOException {
testAll(io.usethesource.vallang.impl.persistent.ValueFactory.getInstance());
testAll(io.usethesource.vallang.impl.fast.ValueFactory.getInstance());
}
public static IMap testOne(IValueFactory vf) throws IOException, FileNotFoundException {
ISet data = | // Path: src/main/java/org/rascalmpl/interpreter/utils/Timing.java
// public final class Timing {
//
// private long start;
//
// public Timing() {
// super();
// }
//
// public void start() {
// start = getCpuTime();
// }
//
// public long duration() {
// long now = getCpuTime();
// long diff = now - start;
// start = now;
// return diff;
// }
//
// public static long getCpuTime() {
// ThreadMXBean bean = ManagementFactory.getThreadMXBean();
// return bean.isCurrentThreadCpuTimeSupported() ?
// bean.getCurrentThreadCpuTime() : 0L;
// }
//
// /**
// * Get user time in nanoseconds.
// */
// public static long getUserTime() {
// ThreadMXBean bean = ManagementFactory.getThreadMXBean();
// return bean.isCurrentThreadCpuTimeSupported() ?
// bean.getCurrentThreadUserTime() : 0L;
// }
//
// /**
// * Get system time in nanoseconds.
// */
// public static long getSystemTime() {
// ThreadMXBean bean = ManagementFactory.getThreadMXBean();
// return bean.isCurrentThreadCpuTimeSupported() ?
// (bean.getCurrentThreadCpuTime() - bean.getCurrentThreadUserTime()) : 0L;
// }
// }
//
// Path: src/main/java/dom/AllDominatorsRunner.java
// public static final String DATA_SET_SINGLE_FILE_NAME = "data/single.bin";
//
// Path: src/main/java/dom/AllDominatorsRunner.java
// public static final boolean LOG_BINARY_RESULTS = false;
//
// Path: src/main/java/dom/AllDominatorsRunner.java
// public static final boolean LOG_TEXTUAL_RESULTS = false;
// Path: src/main/java/dom/DominatorsPDB.java
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import io.usethesource.capsule.Set;
import io.usethesource.capsule.Set.Transient;
import io.usethesource.vallang.IConstructor;
import io.usethesource.vallang.IMap;
import io.usethesource.vallang.IMapWriter;
import io.usethesource.vallang.ISet;
import io.usethesource.vallang.ISetWriter;
import io.usethesource.vallang.ITuple;
import io.usethesource.vallang.IValue;
import io.usethesource.vallang.IValueFactory;
import io.usethesource.vallang.io.StandardTextWriter;
import io.usethesource.vallang.io.old.BinaryValueReader;
import io.usethesource.vallang.io.old.BinaryValueWriter;
import org.rascalmpl.interpreter.utils.Timing;
import static dom.AllDominatorsRunner.CURRENT_DATA_SET_FILE_NAME;
import static dom.AllDominatorsRunner.DATA_SET_SINGLE_FILE_NAME;
import static dom.AllDominatorsRunner.LOG_BINARY_RESULTS;
import static dom.AllDominatorsRunner.LOG_TEXTUAL_RESULTS;
// throw new RuntimeException("not the right type: " + sos.getType());
// }
ISet intersected = intersect(sos);
// if (!intersected.getType().isSet() ||
// !intersected.getType().getElementType().isAbstractData()) {
// throw new RuntimeException("not the right type: " + intersected.getType());
// }
ISet newValue = vf.set(n).union(intersected);
// if (!newValue.getElementType().isAbstractData()) {
// System.err.println("problem");
// }
newDom.put(n, newValue);
}
// if (!newDom.done().getValueType().getElementType().isAbstractData()) {
// System.err.println("not good");
// }
dom = newDom.done();
}
return dom;
}
public static void main(String[] args) throws FileNotFoundException, IOException {
testAll(io.usethesource.vallang.impl.persistent.ValueFactory.getInstance());
testAll(io.usethesource.vallang.impl.fast.ValueFactory.getInstance());
}
public static IMap testOne(IValueFactory vf) throws IOException, FileNotFoundException {
ISet data = | (ISet) new BinaryValueReader().read(vf, new FileInputStream(DATA_SET_SINGLE_FILE_NAME)); |
msteindorfer/criterion | src/main/java/dom/DominatorsPDB.java | // Path: src/main/java/org/rascalmpl/interpreter/utils/Timing.java
// public final class Timing {
//
// private long start;
//
// public Timing() {
// super();
// }
//
// public void start() {
// start = getCpuTime();
// }
//
// public long duration() {
// long now = getCpuTime();
// long diff = now - start;
// start = now;
// return diff;
// }
//
// public static long getCpuTime() {
// ThreadMXBean bean = ManagementFactory.getThreadMXBean();
// return bean.isCurrentThreadCpuTimeSupported() ?
// bean.getCurrentThreadCpuTime() : 0L;
// }
//
// /**
// * Get user time in nanoseconds.
// */
// public static long getUserTime() {
// ThreadMXBean bean = ManagementFactory.getThreadMXBean();
// return bean.isCurrentThreadCpuTimeSupported() ?
// bean.getCurrentThreadUserTime() : 0L;
// }
//
// /**
// * Get system time in nanoseconds.
// */
// public static long getSystemTime() {
// ThreadMXBean bean = ManagementFactory.getThreadMXBean();
// return bean.isCurrentThreadCpuTimeSupported() ?
// (bean.getCurrentThreadCpuTime() - bean.getCurrentThreadUserTime()) : 0L;
// }
// }
//
// Path: src/main/java/dom/AllDominatorsRunner.java
// public static final String DATA_SET_SINGLE_FILE_NAME = "data/single.bin";
//
// Path: src/main/java/dom/AllDominatorsRunner.java
// public static final boolean LOG_BINARY_RESULTS = false;
//
// Path: src/main/java/dom/AllDominatorsRunner.java
// public static final boolean LOG_TEXTUAL_RESULTS = false;
| import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import io.usethesource.capsule.Set;
import io.usethesource.capsule.Set.Transient;
import io.usethesource.vallang.IConstructor;
import io.usethesource.vallang.IMap;
import io.usethesource.vallang.IMapWriter;
import io.usethesource.vallang.ISet;
import io.usethesource.vallang.ISetWriter;
import io.usethesource.vallang.ITuple;
import io.usethesource.vallang.IValue;
import io.usethesource.vallang.IValueFactory;
import io.usethesource.vallang.io.StandardTextWriter;
import io.usethesource.vallang.io.old.BinaryValueReader;
import io.usethesource.vallang.io.old.BinaryValueWriter;
import org.rascalmpl.interpreter.utils.Timing;
import static dom.AllDominatorsRunner.CURRENT_DATA_SET_FILE_NAME;
import static dom.AllDominatorsRunner.DATA_SET_SINGLE_FILE_NAME;
import static dom.AllDominatorsRunner.LOG_BINARY_RESULTS;
import static dom.AllDominatorsRunner.LOG_TEXTUAL_RESULTS; | ISet intersected = intersect(sos);
// if (!intersected.getType().isSet() ||
// !intersected.getType().getElementType().isAbstractData()) {
// throw new RuntimeException("not the right type: " + intersected.getType());
// }
ISet newValue = vf.set(n).union(intersected);
// if (!newValue.getElementType().isAbstractData()) {
// System.err.println("problem");
// }
newDom.put(n, newValue);
}
// if (!newDom.done().getValueType().getElementType().isAbstractData()) {
// System.err.println("not good");
// }
dom = newDom.done();
}
return dom;
}
public static void main(String[] args) throws FileNotFoundException, IOException {
testAll(io.usethesource.vallang.impl.persistent.ValueFactory.getInstance());
testAll(io.usethesource.vallang.impl.fast.ValueFactory.getInstance());
}
public static IMap testOne(IValueFactory vf) throws IOException, FileNotFoundException {
ISet data =
(ISet) new BinaryValueReader().read(vf, new FileInputStream(DATA_SET_SINGLE_FILE_NAME));
| // Path: src/main/java/org/rascalmpl/interpreter/utils/Timing.java
// public final class Timing {
//
// private long start;
//
// public Timing() {
// super();
// }
//
// public void start() {
// start = getCpuTime();
// }
//
// public long duration() {
// long now = getCpuTime();
// long diff = now - start;
// start = now;
// return diff;
// }
//
// public static long getCpuTime() {
// ThreadMXBean bean = ManagementFactory.getThreadMXBean();
// return bean.isCurrentThreadCpuTimeSupported() ?
// bean.getCurrentThreadCpuTime() : 0L;
// }
//
// /**
// * Get user time in nanoseconds.
// */
// public static long getUserTime() {
// ThreadMXBean bean = ManagementFactory.getThreadMXBean();
// return bean.isCurrentThreadCpuTimeSupported() ?
// bean.getCurrentThreadUserTime() : 0L;
// }
//
// /**
// * Get system time in nanoseconds.
// */
// public static long getSystemTime() {
// ThreadMXBean bean = ManagementFactory.getThreadMXBean();
// return bean.isCurrentThreadCpuTimeSupported() ?
// (bean.getCurrentThreadCpuTime() - bean.getCurrentThreadUserTime()) : 0L;
// }
// }
//
// Path: src/main/java/dom/AllDominatorsRunner.java
// public static final String DATA_SET_SINGLE_FILE_NAME = "data/single.bin";
//
// Path: src/main/java/dom/AllDominatorsRunner.java
// public static final boolean LOG_BINARY_RESULTS = false;
//
// Path: src/main/java/dom/AllDominatorsRunner.java
// public static final boolean LOG_TEXTUAL_RESULTS = false;
// Path: src/main/java/dom/DominatorsPDB.java
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import io.usethesource.capsule.Set;
import io.usethesource.capsule.Set.Transient;
import io.usethesource.vallang.IConstructor;
import io.usethesource.vallang.IMap;
import io.usethesource.vallang.IMapWriter;
import io.usethesource.vallang.ISet;
import io.usethesource.vallang.ISetWriter;
import io.usethesource.vallang.ITuple;
import io.usethesource.vallang.IValue;
import io.usethesource.vallang.IValueFactory;
import io.usethesource.vallang.io.StandardTextWriter;
import io.usethesource.vallang.io.old.BinaryValueReader;
import io.usethesource.vallang.io.old.BinaryValueWriter;
import org.rascalmpl.interpreter.utils.Timing;
import static dom.AllDominatorsRunner.CURRENT_DATA_SET_FILE_NAME;
import static dom.AllDominatorsRunner.DATA_SET_SINGLE_FILE_NAME;
import static dom.AllDominatorsRunner.LOG_BINARY_RESULTS;
import static dom.AllDominatorsRunner.LOG_TEXTUAL_RESULTS;
ISet intersected = intersect(sos);
// if (!intersected.getType().isSet() ||
// !intersected.getType().getElementType().isAbstractData()) {
// throw new RuntimeException("not the right type: " + intersected.getType());
// }
ISet newValue = vf.set(n).union(intersected);
// if (!newValue.getElementType().isAbstractData()) {
// System.err.println("problem");
// }
newDom.put(n, newValue);
}
// if (!newDom.done().getValueType().getElementType().isAbstractData()) {
// System.err.println("not good");
// }
dom = newDom.done();
}
return dom;
}
public static void main(String[] args) throws FileNotFoundException, IOException {
testAll(io.usethesource.vallang.impl.persistent.ValueFactory.getInstance());
testAll(io.usethesource.vallang.impl.fast.ValueFactory.getInstance());
}
public static IMap testOne(IValueFactory vf) throws IOException, FileNotFoundException {
ISet data =
(ISet) new BinaryValueReader().read(vf, new FileInputStream(DATA_SET_SINGLE_FILE_NAME));
| long before = Timing.getCpuTime(); |
msteindorfer/criterion | src/main/java/dom/DominatorsPDB.java | // Path: src/main/java/org/rascalmpl/interpreter/utils/Timing.java
// public final class Timing {
//
// private long start;
//
// public Timing() {
// super();
// }
//
// public void start() {
// start = getCpuTime();
// }
//
// public long duration() {
// long now = getCpuTime();
// long diff = now - start;
// start = now;
// return diff;
// }
//
// public static long getCpuTime() {
// ThreadMXBean bean = ManagementFactory.getThreadMXBean();
// return bean.isCurrentThreadCpuTimeSupported() ?
// bean.getCurrentThreadCpuTime() : 0L;
// }
//
// /**
// * Get user time in nanoseconds.
// */
// public static long getUserTime() {
// ThreadMXBean bean = ManagementFactory.getThreadMXBean();
// return bean.isCurrentThreadCpuTimeSupported() ?
// bean.getCurrentThreadUserTime() : 0L;
// }
//
// /**
// * Get system time in nanoseconds.
// */
// public static long getSystemTime() {
// ThreadMXBean bean = ManagementFactory.getThreadMXBean();
// return bean.isCurrentThreadCpuTimeSupported() ?
// (bean.getCurrentThreadCpuTime() - bean.getCurrentThreadUserTime()) : 0L;
// }
// }
//
// Path: src/main/java/dom/AllDominatorsRunner.java
// public static final String DATA_SET_SINGLE_FILE_NAME = "data/single.bin";
//
// Path: src/main/java/dom/AllDominatorsRunner.java
// public static final boolean LOG_BINARY_RESULTS = false;
//
// Path: src/main/java/dom/AllDominatorsRunner.java
// public static final boolean LOG_TEXTUAL_RESULTS = false;
| import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import io.usethesource.capsule.Set;
import io.usethesource.capsule.Set.Transient;
import io.usethesource.vallang.IConstructor;
import io.usethesource.vallang.IMap;
import io.usethesource.vallang.IMapWriter;
import io.usethesource.vallang.ISet;
import io.usethesource.vallang.ISetWriter;
import io.usethesource.vallang.ITuple;
import io.usethesource.vallang.IValue;
import io.usethesource.vallang.IValueFactory;
import io.usethesource.vallang.io.StandardTextWriter;
import io.usethesource.vallang.io.old.BinaryValueReader;
import io.usethesource.vallang.io.old.BinaryValueWriter;
import org.rascalmpl.interpreter.utils.Timing;
import static dom.AllDominatorsRunner.CURRENT_DATA_SET_FILE_NAME;
import static dom.AllDominatorsRunner.DATA_SET_SINGLE_FILE_NAME;
import static dom.AllDominatorsRunner.LOG_BINARY_RESULTS;
import static dom.AllDominatorsRunner.LOG_TEXTUAL_RESULTS; | // if (!newValue.getElementType().isAbstractData()) {
// System.err.println("problem");
// }
newDom.put(n, newValue);
}
// if (!newDom.done().getValueType().getElementType().isAbstractData()) {
// System.err.println("not good");
// }
dom = newDom.done();
}
return dom;
}
public static void main(String[] args) throws FileNotFoundException, IOException {
testAll(io.usethesource.vallang.impl.persistent.ValueFactory.getInstance());
testAll(io.usethesource.vallang.impl.fast.ValueFactory.getInstance());
}
public static IMap testOne(IValueFactory vf) throws IOException, FileNotFoundException {
ISet data =
(ISet) new BinaryValueReader().read(vf, new FileInputStream(DATA_SET_SINGLE_FILE_NAME));
long before = Timing.getCpuTime();
IMap pdbResults = new DominatorsPDB(vf).jDominators(data);
System.err.println(vf.toString() + "\nDuration: "
+ ((Timing.getCpuTime() - before) / 1000000000) + " seconds\n");
| // Path: src/main/java/org/rascalmpl/interpreter/utils/Timing.java
// public final class Timing {
//
// private long start;
//
// public Timing() {
// super();
// }
//
// public void start() {
// start = getCpuTime();
// }
//
// public long duration() {
// long now = getCpuTime();
// long diff = now - start;
// start = now;
// return diff;
// }
//
// public static long getCpuTime() {
// ThreadMXBean bean = ManagementFactory.getThreadMXBean();
// return bean.isCurrentThreadCpuTimeSupported() ?
// bean.getCurrentThreadCpuTime() : 0L;
// }
//
// /**
// * Get user time in nanoseconds.
// */
// public static long getUserTime() {
// ThreadMXBean bean = ManagementFactory.getThreadMXBean();
// return bean.isCurrentThreadCpuTimeSupported() ?
// bean.getCurrentThreadUserTime() : 0L;
// }
//
// /**
// * Get system time in nanoseconds.
// */
// public static long getSystemTime() {
// ThreadMXBean bean = ManagementFactory.getThreadMXBean();
// return bean.isCurrentThreadCpuTimeSupported() ?
// (bean.getCurrentThreadCpuTime() - bean.getCurrentThreadUserTime()) : 0L;
// }
// }
//
// Path: src/main/java/dom/AllDominatorsRunner.java
// public static final String DATA_SET_SINGLE_FILE_NAME = "data/single.bin";
//
// Path: src/main/java/dom/AllDominatorsRunner.java
// public static final boolean LOG_BINARY_RESULTS = false;
//
// Path: src/main/java/dom/AllDominatorsRunner.java
// public static final boolean LOG_TEXTUAL_RESULTS = false;
// Path: src/main/java/dom/DominatorsPDB.java
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import io.usethesource.capsule.Set;
import io.usethesource.capsule.Set.Transient;
import io.usethesource.vallang.IConstructor;
import io.usethesource.vallang.IMap;
import io.usethesource.vallang.IMapWriter;
import io.usethesource.vallang.ISet;
import io.usethesource.vallang.ISetWriter;
import io.usethesource.vallang.ITuple;
import io.usethesource.vallang.IValue;
import io.usethesource.vallang.IValueFactory;
import io.usethesource.vallang.io.StandardTextWriter;
import io.usethesource.vallang.io.old.BinaryValueReader;
import io.usethesource.vallang.io.old.BinaryValueWriter;
import org.rascalmpl.interpreter.utils.Timing;
import static dom.AllDominatorsRunner.CURRENT_DATA_SET_FILE_NAME;
import static dom.AllDominatorsRunner.DATA_SET_SINGLE_FILE_NAME;
import static dom.AllDominatorsRunner.LOG_BINARY_RESULTS;
import static dom.AllDominatorsRunner.LOG_TEXTUAL_RESULTS;
// if (!newValue.getElementType().isAbstractData()) {
// System.err.println("problem");
// }
newDom.put(n, newValue);
}
// if (!newDom.done().getValueType().getElementType().isAbstractData()) {
// System.err.println("not good");
// }
dom = newDom.done();
}
return dom;
}
public static void main(String[] args) throws FileNotFoundException, IOException {
testAll(io.usethesource.vallang.impl.persistent.ValueFactory.getInstance());
testAll(io.usethesource.vallang.impl.fast.ValueFactory.getInstance());
}
public static IMap testOne(IValueFactory vf) throws IOException, FileNotFoundException {
ISet data =
(ISet) new BinaryValueReader().read(vf, new FileInputStream(DATA_SET_SINGLE_FILE_NAME));
long before = Timing.getCpuTime();
IMap pdbResults = new DominatorsPDB(vf).jDominators(data);
System.err.println(vf.toString() + "\nDuration: "
+ ((Timing.getCpuTime() - before) / 1000000000) + " seconds\n");
| if (LOG_BINARY_RESULTS) { |
msteindorfer/criterion | src/main/java/dom/DominatorsPDB.java | // Path: src/main/java/org/rascalmpl/interpreter/utils/Timing.java
// public final class Timing {
//
// private long start;
//
// public Timing() {
// super();
// }
//
// public void start() {
// start = getCpuTime();
// }
//
// public long duration() {
// long now = getCpuTime();
// long diff = now - start;
// start = now;
// return diff;
// }
//
// public static long getCpuTime() {
// ThreadMXBean bean = ManagementFactory.getThreadMXBean();
// return bean.isCurrentThreadCpuTimeSupported() ?
// bean.getCurrentThreadCpuTime() : 0L;
// }
//
// /**
// * Get user time in nanoseconds.
// */
// public static long getUserTime() {
// ThreadMXBean bean = ManagementFactory.getThreadMXBean();
// return bean.isCurrentThreadCpuTimeSupported() ?
// bean.getCurrentThreadUserTime() : 0L;
// }
//
// /**
// * Get system time in nanoseconds.
// */
// public static long getSystemTime() {
// ThreadMXBean bean = ManagementFactory.getThreadMXBean();
// return bean.isCurrentThreadCpuTimeSupported() ?
// (bean.getCurrentThreadCpuTime() - bean.getCurrentThreadUserTime()) : 0L;
// }
// }
//
// Path: src/main/java/dom/AllDominatorsRunner.java
// public static final String DATA_SET_SINGLE_FILE_NAME = "data/single.bin";
//
// Path: src/main/java/dom/AllDominatorsRunner.java
// public static final boolean LOG_BINARY_RESULTS = false;
//
// Path: src/main/java/dom/AllDominatorsRunner.java
// public static final boolean LOG_TEXTUAL_RESULTS = false;
| import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import io.usethesource.capsule.Set;
import io.usethesource.capsule.Set.Transient;
import io.usethesource.vallang.IConstructor;
import io.usethesource.vallang.IMap;
import io.usethesource.vallang.IMapWriter;
import io.usethesource.vallang.ISet;
import io.usethesource.vallang.ISetWriter;
import io.usethesource.vallang.ITuple;
import io.usethesource.vallang.IValue;
import io.usethesource.vallang.IValueFactory;
import io.usethesource.vallang.io.StandardTextWriter;
import io.usethesource.vallang.io.old.BinaryValueReader;
import io.usethesource.vallang.io.old.BinaryValueWriter;
import org.rascalmpl.interpreter.utils.Timing;
import static dom.AllDominatorsRunner.CURRENT_DATA_SET_FILE_NAME;
import static dom.AllDominatorsRunner.DATA_SET_SINGLE_FILE_NAME;
import static dom.AllDominatorsRunner.LOG_BINARY_RESULTS;
import static dom.AllDominatorsRunner.LOG_TEXTUAL_RESULTS; |
// if (!newDom.done().getValueType().getElementType().isAbstractData()) {
// System.err.println("not good");
// }
dom = newDom.done();
}
return dom;
}
public static void main(String[] args) throws FileNotFoundException, IOException {
testAll(io.usethesource.vallang.impl.persistent.ValueFactory.getInstance());
testAll(io.usethesource.vallang.impl.fast.ValueFactory.getInstance());
}
public static IMap testOne(IValueFactory vf) throws IOException, FileNotFoundException {
ISet data =
(ISet) new BinaryValueReader().read(vf, new FileInputStream(DATA_SET_SINGLE_FILE_NAME));
long before = Timing.getCpuTime();
IMap pdbResults = new DominatorsPDB(vf).jDominators(data);
System.err.println(vf.toString() + "\nDuration: "
+ ((Timing.getCpuTime() - before) / 1000000000) + " seconds\n");
if (LOG_BINARY_RESULTS) {
new BinaryValueWriter().write(pdbResults,
new FileOutputStream("data/dominators-java-" + vf.toString() + "-single.bin"));
}
| // Path: src/main/java/org/rascalmpl/interpreter/utils/Timing.java
// public final class Timing {
//
// private long start;
//
// public Timing() {
// super();
// }
//
// public void start() {
// start = getCpuTime();
// }
//
// public long duration() {
// long now = getCpuTime();
// long diff = now - start;
// start = now;
// return diff;
// }
//
// public static long getCpuTime() {
// ThreadMXBean bean = ManagementFactory.getThreadMXBean();
// return bean.isCurrentThreadCpuTimeSupported() ?
// bean.getCurrentThreadCpuTime() : 0L;
// }
//
// /**
// * Get user time in nanoseconds.
// */
// public static long getUserTime() {
// ThreadMXBean bean = ManagementFactory.getThreadMXBean();
// return bean.isCurrentThreadCpuTimeSupported() ?
// bean.getCurrentThreadUserTime() : 0L;
// }
//
// /**
// * Get system time in nanoseconds.
// */
// public static long getSystemTime() {
// ThreadMXBean bean = ManagementFactory.getThreadMXBean();
// return bean.isCurrentThreadCpuTimeSupported() ?
// (bean.getCurrentThreadCpuTime() - bean.getCurrentThreadUserTime()) : 0L;
// }
// }
//
// Path: src/main/java/dom/AllDominatorsRunner.java
// public static final String DATA_SET_SINGLE_FILE_NAME = "data/single.bin";
//
// Path: src/main/java/dom/AllDominatorsRunner.java
// public static final boolean LOG_BINARY_RESULTS = false;
//
// Path: src/main/java/dom/AllDominatorsRunner.java
// public static final boolean LOG_TEXTUAL_RESULTS = false;
// Path: src/main/java/dom/DominatorsPDB.java
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import io.usethesource.capsule.Set;
import io.usethesource.capsule.Set.Transient;
import io.usethesource.vallang.IConstructor;
import io.usethesource.vallang.IMap;
import io.usethesource.vallang.IMapWriter;
import io.usethesource.vallang.ISet;
import io.usethesource.vallang.ISetWriter;
import io.usethesource.vallang.ITuple;
import io.usethesource.vallang.IValue;
import io.usethesource.vallang.IValueFactory;
import io.usethesource.vallang.io.StandardTextWriter;
import io.usethesource.vallang.io.old.BinaryValueReader;
import io.usethesource.vallang.io.old.BinaryValueWriter;
import org.rascalmpl.interpreter.utils.Timing;
import static dom.AllDominatorsRunner.CURRENT_DATA_SET_FILE_NAME;
import static dom.AllDominatorsRunner.DATA_SET_SINGLE_FILE_NAME;
import static dom.AllDominatorsRunner.LOG_BINARY_RESULTS;
import static dom.AllDominatorsRunner.LOG_TEXTUAL_RESULTS;
// if (!newDom.done().getValueType().getElementType().isAbstractData()) {
// System.err.println("not good");
// }
dom = newDom.done();
}
return dom;
}
public static void main(String[] args) throws FileNotFoundException, IOException {
testAll(io.usethesource.vallang.impl.persistent.ValueFactory.getInstance());
testAll(io.usethesource.vallang.impl.fast.ValueFactory.getInstance());
}
public static IMap testOne(IValueFactory vf) throws IOException, FileNotFoundException {
ISet data =
(ISet) new BinaryValueReader().read(vf, new FileInputStream(DATA_SET_SINGLE_FILE_NAME));
long before = Timing.getCpuTime();
IMap pdbResults = new DominatorsPDB(vf).jDominators(data);
System.err.println(vf.toString() + "\nDuration: "
+ ((Timing.getCpuTime() - before) / 1000000000) + " seconds\n");
if (LOG_BINARY_RESULTS) {
new BinaryValueWriter().write(pdbResults,
new FileOutputStream("data/dominators-java-" + vf.toString() + "-single.bin"));
}
| if (LOG_TEXTUAL_RESULTS) { |
msteindorfer/criterion | src/main/java/io/usethesource/criterion/impl/persistent/champ/ChampMapBuilder.java | // Path: src/main/java/io/usethesource/capsule/MapFactory.java
// public class MapFactory {
//
// // private final Class<? extends Immutable<?, ?>> targetClass;
//
// private final Method persistentMapOfEmpty;
// private final Method persistentMapOfKeyValuePairs;
//
// private final Method transientMapOfEmpty;
// private final Method transientMapOfKeyValuePairs;
//
// public MapFactory(Class<?> targetClass) {
// // this.targetClass = targetClass;
//
// try {
// persistentMapOfEmpty = targetClass.getMethod("of");
// persistentMapOfKeyValuePairs = targetClass.getMethod("of", Object[].class);
//
// transientMapOfEmpty = targetClass.getMethod("transientOf");
// transientMapOfKeyValuePairs = targetClass.getMethod("transientOf", Object[].class);
// } catch (NoSuchMethodException | SecurityException e) {
// e.printStackTrace();
// throw new RuntimeException(e);
// }
// }
//
// // public Class<? extends Immutable<?, ?>> getTargetClass() {
// // return targetClass;
// // }
//
// @SuppressWarnings("unchecked")
// public final <K, V> Map.Immutable<K, V> of() {
// try {
// return (Map.Immutable<K, V>) persistentMapOfEmpty.invoke(null);
// } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
// throw new RuntimeException(e);
// }
// }
//
// public final <K, V> Map.Immutable<K, V> of(Object... keyValuePairs) {
// try {
// return (Map.Immutable<K, V>) persistentMapOfKeyValuePairs
// .invoke(null, (Object) keyValuePairs);
// } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
// throw new RuntimeException(e);
// }
// }
//
// @SuppressWarnings("unchecked")
// public final <K, V> Map.Transient<K, V> transientOf() {
// try {
// return (Map.Transient<K, V>) transientMapOfEmpty.invoke(null);
// } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
// throw new RuntimeException(e);
// }
// }
//
// @SuppressWarnings("unchecked")
// public final <K, V> Map.Transient<K, V> transientOf(Object... keyValuePairs) {
// try {
// return (Map.Transient<K, V>) transientMapOfKeyValuePairs.invoke(null, (Object) keyValuePairs);
// } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
// e.printStackTrace();
// throw new RuntimeException(e);
// }
// }
//
// }
//
// Path: src/main/java/io/usethesource/criterion/api/JmhValue.java
// @CompilerControl(Mode.DONT_INLINE)
// public interface JmhValue {
//
// /**
// * Removes the JmhValue delegation object to reveal its internal representation.
// *
// * @return internal representation
// */
// Object unwrap();
//
// }
//
// Path: src/main/java/io/usethesource/criterion/impl/AbstractMapBuilder.java
// public class AbstractMapBuilder<C extends JmhValue, CC> implements JmhMap.Builder {
//
// protected CC mapContent;
// protected JmhMap constructedMap;
//
// final Function<CC, JmhMap> functionWrap;
// final Function<CC, BiFunction<JmhValue, JmhValue, CC>> methodInsert;
//
// public AbstractMapBuilder(final CC empty,
// final Function<CC, BiFunction<JmhValue, JmhValue, CC>> methodInsert,
// final Function<CC, JmhMap> functionWrap) {
//
// this.mapContent = empty;
// this.constructedMap = null;
//
// this.methodInsert = methodInsert;
// this.functionWrap = functionWrap;
// }
//
// @Override
// public final void put(JmhValue key, JmhValue value) {
// checkMutation();
// mapContent = methodInsert.apply(mapContent).apply(key, value);
// }
//
// @Override
// public final void putAll(JmhMap map) {
// putAll(map.entryIterator());
// }
//
// @Override
// public final void putAll(java.util.Map<JmhValue, JmhValue> map) {
// putAll(map.entrySet().iterator());
// }
//
// private final void putAll(Iterator<Entry<JmhValue, JmhValue>> entryIterator) {
// checkMutation();
//
// while (entryIterator.hasNext()) {
// final Entry<JmhValue, JmhValue> entry = entryIterator.next();
// final JmhValue key = entry.getKey();
// final JmhValue value = entry.getValue();
//
// put(key, value);
// }
// }
//
// private void checkMutation() {
// if (constructedMap != null) {
// throw new UnsupportedOperationException("Mutation of a finalized map is not supported.");
// }
// }
//
// @Override
// public final JmhMap done() {
// if (constructedMap == null) {
// constructedMap = functionWrap.apply(mapContent);
// }
//
// return constructedMap;
// }
//
// }
| import io.usethesource.capsule.Map;
import io.usethesource.capsule.MapFactory;
import io.usethesource.criterion.api.JmhValue;
import io.usethesource.criterion.impl.AbstractMapBuilder; | /**
* Copyright (c) Michael Steindorfer <Centrum Wiskunde & Informatica> and Contributors.
* All rights reserved.
*
* This file is licensed under the BSD 2-Clause License, which accompanies this project
* and is available under https://opensource.org/licenses/BSD-2-Clause.
*/
package io.usethesource.criterion.impl.persistent.champ;
final class ChampMapBuilder extends
AbstractMapBuilder<JmhValue, Map.Immutable<JmhValue, JmhValue>> {
| // Path: src/main/java/io/usethesource/capsule/MapFactory.java
// public class MapFactory {
//
// // private final Class<? extends Immutable<?, ?>> targetClass;
//
// private final Method persistentMapOfEmpty;
// private final Method persistentMapOfKeyValuePairs;
//
// private final Method transientMapOfEmpty;
// private final Method transientMapOfKeyValuePairs;
//
// public MapFactory(Class<?> targetClass) {
// // this.targetClass = targetClass;
//
// try {
// persistentMapOfEmpty = targetClass.getMethod("of");
// persistentMapOfKeyValuePairs = targetClass.getMethod("of", Object[].class);
//
// transientMapOfEmpty = targetClass.getMethod("transientOf");
// transientMapOfKeyValuePairs = targetClass.getMethod("transientOf", Object[].class);
// } catch (NoSuchMethodException | SecurityException e) {
// e.printStackTrace();
// throw new RuntimeException(e);
// }
// }
//
// // public Class<? extends Immutable<?, ?>> getTargetClass() {
// // return targetClass;
// // }
//
// @SuppressWarnings("unchecked")
// public final <K, V> Map.Immutable<K, V> of() {
// try {
// return (Map.Immutable<K, V>) persistentMapOfEmpty.invoke(null);
// } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
// throw new RuntimeException(e);
// }
// }
//
// public final <K, V> Map.Immutable<K, V> of(Object... keyValuePairs) {
// try {
// return (Map.Immutable<K, V>) persistentMapOfKeyValuePairs
// .invoke(null, (Object) keyValuePairs);
// } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
// throw new RuntimeException(e);
// }
// }
//
// @SuppressWarnings("unchecked")
// public final <K, V> Map.Transient<K, V> transientOf() {
// try {
// return (Map.Transient<K, V>) transientMapOfEmpty.invoke(null);
// } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
// throw new RuntimeException(e);
// }
// }
//
// @SuppressWarnings("unchecked")
// public final <K, V> Map.Transient<K, V> transientOf(Object... keyValuePairs) {
// try {
// return (Map.Transient<K, V>) transientMapOfKeyValuePairs.invoke(null, (Object) keyValuePairs);
// } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
// e.printStackTrace();
// throw new RuntimeException(e);
// }
// }
//
// }
//
// Path: src/main/java/io/usethesource/criterion/api/JmhValue.java
// @CompilerControl(Mode.DONT_INLINE)
// public interface JmhValue {
//
// /**
// * Removes the JmhValue delegation object to reveal its internal representation.
// *
// * @return internal representation
// */
// Object unwrap();
//
// }
//
// Path: src/main/java/io/usethesource/criterion/impl/AbstractMapBuilder.java
// public class AbstractMapBuilder<C extends JmhValue, CC> implements JmhMap.Builder {
//
// protected CC mapContent;
// protected JmhMap constructedMap;
//
// final Function<CC, JmhMap> functionWrap;
// final Function<CC, BiFunction<JmhValue, JmhValue, CC>> methodInsert;
//
// public AbstractMapBuilder(final CC empty,
// final Function<CC, BiFunction<JmhValue, JmhValue, CC>> methodInsert,
// final Function<CC, JmhMap> functionWrap) {
//
// this.mapContent = empty;
// this.constructedMap = null;
//
// this.methodInsert = methodInsert;
// this.functionWrap = functionWrap;
// }
//
// @Override
// public final void put(JmhValue key, JmhValue value) {
// checkMutation();
// mapContent = methodInsert.apply(mapContent).apply(key, value);
// }
//
// @Override
// public final void putAll(JmhMap map) {
// putAll(map.entryIterator());
// }
//
// @Override
// public final void putAll(java.util.Map<JmhValue, JmhValue> map) {
// putAll(map.entrySet().iterator());
// }
//
// private final void putAll(Iterator<Entry<JmhValue, JmhValue>> entryIterator) {
// checkMutation();
//
// while (entryIterator.hasNext()) {
// final Entry<JmhValue, JmhValue> entry = entryIterator.next();
// final JmhValue key = entry.getKey();
// final JmhValue value = entry.getValue();
//
// put(key, value);
// }
// }
//
// private void checkMutation() {
// if (constructedMap != null) {
// throw new UnsupportedOperationException("Mutation of a finalized map is not supported.");
// }
// }
//
// @Override
// public final JmhMap done() {
// if (constructedMap == null) {
// constructedMap = functionWrap.apply(mapContent);
// }
//
// return constructedMap;
// }
//
// }
// Path: src/main/java/io/usethesource/criterion/impl/persistent/champ/ChampMapBuilder.java
import io.usethesource.capsule.Map;
import io.usethesource.capsule.MapFactory;
import io.usethesource.criterion.api.JmhValue;
import io.usethesource.criterion.impl.AbstractMapBuilder;
/**
* Copyright (c) Michael Steindorfer <Centrum Wiskunde & Informatica> and Contributors.
* All rights reserved.
*
* This file is licensed under the BSD 2-Clause License, which accompanies this project
* and is available under https://opensource.org/licenses/BSD-2-Clause.
*/
package io.usethesource.criterion.impl.persistent.champ;
final class ChampMapBuilder extends
AbstractMapBuilder<JmhValue, Map.Immutable<JmhValue, JmhValue>> {
| ChampMapBuilder(MapFactory mapFactory) { |
msteindorfer/criterion | src/main/java/io/usethesource/criterion/impl/persistent/clojure/ClojureSetMultimap.java | // Path: src/main/java/io/usethesource/criterion/api/JmhSetMultimap.java
// public interface JmhSetMultimap extends JmhValue { // Iterable<JmhValue>
//
// boolean isEmpty();
//
// int size();
//
// JmhSetMultimap insert(JmhValue key, JmhValue value);
//
// JmhSetMultimap remove(JmhValue key, JmhValue value);
//
// JmhSetMultimap put(JmhValue key, JmhValue value);
//
// JmhSetMultimap remove(JmhValue key);
//
// boolean containsKey(JmhValue key);
//
// boolean containsValue(JmhValue value);
//
// boolean contains(JmhValue key, JmhValue value);
//
// // JmhValue get(JmhValue key);
// //
// // boolean containsValue(JmhValue value);
//
// Iterator<JmhValue> iterator();
//
// // Iterator<JmhValue> valueIterator();
//
// Iterator<Entry<JmhValue, JmhValue>> entryIterator();
//
// Iterator<Entry<JmhValue, Object>> nativeEntryIterator();
//
// java.util.Set<JmhValue> keySet();
//
// public static interface Builder extends JmhBuilder {
//
// void insert(JmhValue key, JmhValue value);
//
// // void putAll(JmhMap map);
// //
// // void putAll(Map<JmhValue, JmhValue> map);
//
// @Override
// JmhSetMultimap done();
//
// }
//
// }
//
// Path: src/main/java/io/usethesource/criterion/api/JmhValue.java
// @CompilerControl(Mode.DONT_INLINE)
// public interface JmhValue {
//
// /**
// * Removes the JmhValue delegation object to reveal its internal representation.
// *
// * @return internal representation
// */
// Object unwrap();
//
// }
| import java.util.Collections;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import clojure.lang.APersistentMap;
import clojure.lang.IPersistentMap;
import clojure.lang.IPersistentSet;
import clojure.lang.PersistentHashSet;
import io.usethesource.criterion.api.JmhSetMultimap;
import io.usethesource.criterion.api.JmhValue;
import static io.usethesource.capsule.util.collection.AbstractSpecialisedImmutableMap.entryOf; | /**
* Copyright (c) Michael Steindorfer <Centrum Wiskunde & Informatica> and Contributors.
* All rights reserved.
*
* This file is licensed under the BSD 2-Clause License, which accompanies this project
* and is available under https://opensource.org/licenses/BSD-2-Clause.
*/
package io.usethesource.criterion.impl.persistent.clojure;
public class ClojureSetMultimap implements JmhSetMultimap {
protected final IPersistentMap xs;
protected ClojureSetMultimap(IPersistentMap xs) {
this.xs = xs;
}
@Override
public boolean isEmpty() {
return size() == 0;
}
@Override
public int size() {
return xs.count(); // TODO: is unique keySet size instead of entrySet size
}
@Override | // Path: src/main/java/io/usethesource/criterion/api/JmhSetMultimap.java
// public interface JmhSetMultimap extends JmhValue { // Iterable<JmhValue>
//
// boolean isEmpty();
//
// int size();
//
// JmhSetMultimap insert(JmhValue key, JmhValue value);
//
// JmhSetMultimap remove(JmhValue key, JmhValue value);
//
// JmhSetMultimap put(JmhValue key, JmhValue value);
//
// JmhSetMultimap remove(JmhValue key);
//
// boolean containsKey(JmhValue key);
//
// boolean containsValue(JmhValue value);
//
// boolean contains(JmhValue key, JmhValue value);
//
// // JmhValue get(JmhValue key);
// //
// // boolean containsValue(JmhValue value);
//
// Iterator<JmhValue> iterator();
//
// // Iterator<JmhValue> valueIterator();
//
// Iterator<Entry<JmhValue, JmhValue>> entryIterator();
//
// Iterator<Entry<JmhValue, Object>> nativeEntryIterator();
//
// java.util.Set<JmhValue> keySet();
//
// public static interface Builder extends JmhBuilder {
//
// void insert(JmhValue key, JmhValue value);
//
// // void putAll(JmhMap map);
// //
// // void putAll(Map<JmhValue, JmhValue> map);
//
// @Override
// JmhSetMultimap done();
//
// }
//
// }
//
// Path: src/main/java/io/usethesource/criterion/api/JmhValue.java
// @CompilerControl(Mode.DONT_INLINE)
// public interface JmhValue {
//
// /**
// * Removes the JmhValue delegation object to reveal its internal representation.
// *
// * @return internal representation
// */
// Object unwrap();
//
// }
// Path: src/main/java/io/usethesource/criterion/impl/persistent/clojure/ClojureSetMultimap.java
import java.util.Collections;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import clojure.lang.APersistentMap;
import clojure.lang.IPersistentMap;
import clojure.lang.IPersistentSet;
import clojure.lang.PersistentHashSet;
import io.usethesource.criterion.api.JmhSetMultimap;
import io.usethesource.criterion.api.JmhValue;
import static io.usethesource.capsule.util.collection.AbstractSpecialisedImmutableMap.entryOf;
/**
* Copyright (c) Michael Steindorfer <Centrum Wiskunde & Informatica> and Contributors.
* All rights reserved.
*
* This file is licensed under the BSD 2-Clause License, which accompanies this project
* and is available under https://opensource.org/licenses/BSD-2-Clause.
*/
package io.usethesource.criterion.impl.persistent.clojure;
public class ClojureSetMultimap implements JmhSetMultimap {
protected final IPersistentMap xs;
protected ClojureSetMultimap(IPersistentMap xs) {
this.xs = xs;
}
@Override
public boolean isEmpty() {
return size() == 0;
}
@Override
public int size() {
return xs.count(); // TODO: is unique keySet size instead of entrySet size
}
@Override | public JmhSetMultimap insert(JmhValue key, JmhValue value) { |
msteindorfer/criterion | src/main/java/io/usethesource/criterion/impl/persistent/clojure/ClojureSet.java | // Path: src/main/java/io/usethesource/criterion/api/JmhSet.java
// public interface JmhSet extends JmhValue, Iterable<JmhValue> {
//
// boolean isEmpty();
//
// int size();
//
// boolean contains(JmhValue element);
//
// JmhSet insert(JmhValue element);
//
// JmhSet delete(JmhValue elem);
//
// default boolean subsetOf(JmhSet other) {
// throw new UnsupportedOperationException();
// }
//
// default JmhSet union(JmhSet other) {
// throw new UnsupportedOperationException();
// }
//
// default JmhSet subtract(JmhSet other) {
// throw new UnsupportedOperationException();
// }
//
// default JmhSet intersect(JmhSet other) {
// throw new UnsupportedOperationException();
// }
//
// @Override
// Iterator<JmhValue> iterator();
//
// @Deprecated
// java.util.Set<JmhValue> asJavaSet();
//
// interface Builder extends JmhBuilder {
//
// @Deprecated
// default void insert(JmhValue value) {
// insert(new JmhValue[]{value});
// }
//
// void insert(JmhValue... v);
//
// void insertAll(Iterable<? extends JmhValue> collection);
//
// @Override
// JmhSet done();
//
// }
//
// }
//
// Path: src/main/java/io/usethesource/criterion/api/JmhValue.java
// @CompilerControl(Mode.DONT_INLINE)
// public interface JmhValue {
//
// /**
// * Removes the JmhValue delegation object to reveal its internal representation.
// *
// * @return internal representation
// */
// Object unwrap();
//
// }
| import clojure.lang.APersistentSet;
import clojure.lang.IPersistentSet;
import clojure.lang.PersistentHashSet;
import io.usethesource.criterion.api.JmhSet;
import io.usethesource.criterion.api.JmhValue;
import java.util.Iterator;
import java.util.Set; | /**
* Copyright (c) Michael Steindorfer <Centrum Wiskunde & Informatica> and Contributors.
* All rights reserved.
*
* This file is licensed under the BSD 2-Clause License, which accompanies this project
* and is available under https://opensource.org/licenses/BSD-2-Clause.
*/
package io.usethesource.criterion.impl.persistent.clojure;
class ClojureSet implements JmhSet {
protected final IPersistentSet xs;
protected ClojureSet(IPersistentSet xs) {
this.xs = xs;
}
protected ClojureSet() {
this(PersistentHashSet.EMPTY);
}
| // Path: src/main/java/io/usethesource/criterion/api/JmhSet.java
// public interface JmhSet extends JmhValue, Iterable<JmhValue> {
//
// boolean isEmpty();
//
// int size();
//
// boolean contains(JmhValue element);
//
// JmhSet insert(JmhValue element);
//
// JmhSet delete(JmhValue elem);
//
// default boolean subsetOf(JmhSet other) {
// throw new UnsupportedOperationException();
// }
//
// default JmhSet union(JmhSet other) {
// throw new UnsupportedOperationException();
// }
//
// default JmhSet subtract(JmhSet other) {
// throw new UnsupportedOperationException();
// }
//
// default JmhSet intersect(JmhSet other) {
// throw new UnsupportedOperationException();
// }
//
// @Override
// Iterator<JmhValue> iterator();
//
// @Deprecated
// java.util.Set<JmhValue> asJavaSet();
//
// interface Builder extends JmhBuilder {
//
// @Deprecated
// default void insert(JmhValue value) {
// insert(new JmhValue[]{value});
// }
//
// void insert(JmhValue... v);
//
// void insertAll(Iterable<? extends JmhValue> collection);
//
// @Override
// JmhSet done();
//
// }
//
// }
//
// Path: src/main/java/io/usethesource/criterion/api/JmhValue.java
// @CompilerControl(Mode.DONT_INLINE)
// public interface JmhValue {
//
// /**
// * Removes the JmhValue delegation object to reveal its internal representation.
// *
// * @return internal representation
// */
// Object unwrap();
//
// }
// Path: src/main/java/io/usethesource/criterion/impl/persistent/clojure/ClojureSet.java
import clojure.lang.APersistentSet;
import clojure.lang.IPersistentSet;
import clojure.lang.PersistentHashSet;
import io.usethesource.criterion.api.JmhSet;
import io.usethesource.criterion.api.JmhValue;
import java.util.Iterator;
import java.util.Set;
/**
* Copyright (c) Michael Steindorfer <Centrum Wiskunde & Informatica> and Contributors.
* All rights reserved.
*
* This file is licensed under the BSD 2-Clause License, which accompanies this project
* and is available under https://opensource.org/licenses/BSD-2-Clause.
*/
package io.usethesource.criterion.impl.persistent.clojure;
class ClojureSet implements JmhSet {
protected final IPersistentSet xs;
protected ClojureSet(IPersistentSet xs) {
this.xs = xs;
}
protected ClojureSet() {
this(PersistentHashSet.EMPTY);
}
| protected ClojureSet(JmhValue... values) { |
msteindorfer/criterion | src/main/java/io/usethesource/criterion/impl/persistent/champ/ChampSetMultimapBuilder.java | // Path: src/main/java/io/usethesource/capsule/SetMultimapFactory.java
// public class SetMultimapFactory {
//
// // private final Class<? extends Immutable<?, ?>> targetClass;
//
// private final Method persistentMapOfEmpty;
// // private final Method persistentMapOfKeyValuePairs;
//
// private final Method transientMapOfEmpty;
// // private final Method transientMapOfKeyValuePairs;
//
// public SetMultimapFactory(Class<?> targetClass) {
// // this.targetClass = targetClass;
//
// try {
// persistentMapOfEmpty = targetClass.getMethod("of");
// // persistentMapOfKeyValuePairs = targetClass.getMethod("of", Object.class, Object[].class);
//
// transientMapOfEmpty = targetClass.getMethod("transientOf");
// // transientMapOfKeyValuePairs = targetClass.getMethod("transientOf", Object.class,
// // Object[].class);
// } catch (NoSuchMethodException | SecurityException e) {
// e.printStackTrace();
// throw new RuntimeException(e);
// }
// }
//
// // public Class<? extends Immutable<?, ?>> getTargetClass() {
// // return targetClass;
// // }
//
// public final <K, V> SetMultimap.Immutable<K, V> of() {
// try {
// return (SetMultimap.Immutable<K, V>) persistentMapOfEmpty.invoke(null);
// } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
// throw new RuntimeException(e);
// }
// }
//
// // @SuppressWarnings("unchecked")
// // public final <K, V> SetMultimap.Immutable<K, V> of(K key, V... values) {
// // try {
// // return (SetMultimap.Immutable<K, V>) persistentMapOfKeyValuePairs.invoke(null, key, values);
// // } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
// // throw new RuntimeException(e);
// // }
// // }
//
// public final <K, V> SetMultimap.Transient<K, V> transientOf() {
// try {
// return (SetMultimap.Transient<K, V>) transientMapOfEmpty.invoke(null);
// } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
// throw new RuntimeException(e);
// }
// }
//
// // @SuppressWarnings("unchecked")
// // public final <K, V> SetMultimap.Transient<K, V> transientOf(K key, V... values) {
// // try {
// // return (SetMultimap.Transient<K, V>) transientMapOfKeyValuePairs.invoke(null, key, values);
// // } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
// // e.printStackTrace();
// // throw new RuntimeException(e);
// // }
// // }
//
// }
//
// Path: src/main/java/io/usethesource/criterion/api/JmhSetMultimap.java
// public interface JmhSetMultimap extends JmhValue { // Iterable<JmhValue>
//
// boolean isEmpty();
//
// int size();
//
// JmhSetMultimap insert(JmhValue key, JmhValue value);
//
// JmhSetMultimap remove(JmhValue key, JmhValue value);
//
// JmhSetMultimap put(JmhValue key, JmhValue value);
//
// JmhSetMultimap remove(JmhValue key);
//
// boolean containsKey(JmhValue key);
//
// boolean containsValue(JmhValue value);
//
// boolean contains(JmhValue key, JmhValue value);
//
// // JmhValue get(JmhValue key);
// //
// // boolean containsValue(JmhValue value);
//
// Iterator<JmhValue> iterator();
//
// // Iterator<JmhValue> valueIterator();
//
// Iterator<Entry<JmhValue, JmhValue>> entryIterator();
//
// Iterator<Entry<JmhValue, Object>> nativeEntryIterator();
//
// java.util.Set<JmhValue> keySet();
//
// public static interface Builder extends JmhBuilder {
//
// void insert(JmhValue key, JmhValue value);
//
// // void putAll(JmhMap map);
// //
// // void putAll(Map<JmhValue, JmhValue> map);
//
// @Override
// JmhSetMultimap done();
//
// }
//
// }
//
// Path: src/main/java/io/usethesource/criterion/api/JmhValue.java
// @CompilerControl(Mode.DONT_INLINE)
// public interface JmhValue {
//
// /**
// * Removes the JmhValue delegation object to reveal its internal representation.
// *
// * @return internal representation
// */
// Object unwrap();
//
// }
| import io.usethesource.capsule.SetMultimap;
import io.usethesource.capsule.SetMultimapFactory;
import io.usethesource.criterion.api.JmhSetMultimap;
import io.usethesource.criterion.api.JmhValue; | /**
* Copyright (c) Michael Steindorfer <Centrum Wiskunde & Informatica> and Contributors.
* All rights reserved.
*
* This file is licensed under the BSD 2-Clause License, which accompanies this project
* and is available under https://opensource.org/licenses/BSD-2-Clause.
*/
package io.usethesource.criterion.impl.persistent.champ;
final class ChampSetMultimapBuilder implements JmhSetMultimap.Builder {
protected SetMultimap.Immutable<JmhValue, JmhValue> mapContent;
protected JmhSetMultimap constructedMap;
| // Path: src/main/java/io/usethesource/capsule/SetMultimapFactory.java
// public class SetMultimapFactory {
//
// // private final Class<? extends Immutable<?, ?>> targetClass;
//
// private final Method persistentMapOfEmpty;
// // private final Method persistentMapOfKeyValuePairs;
//
// private final Method transientMapOfEmpty;
// // private final Method transientMapOfKeyValuePairs;
//
// public SetMultimapFactory(Class<?> targetClass) {
// // this.targetClass = targetClass;
//
// try {
// persistentMapOfEmpty = targetClass.getMethod("of");
// // persistentMapOfKeyValuePairs = targetClass.getMethod("of", Object.class, Object[].class);
//
// transientMapOfEmpty = targetClass.getMethod("transientOf");
// // transientMapOfKeyValuePairs = targetClass.getMethod("transientOf", Object.class,
// // Object[].class);
// } catch (NoSuchMethodException | SecurityException e) {
// e.printStackTrace();
// throw new RuntimeException(e);
// }
// }
//
// // public Class<? extends Immutable<?, ?>> getTargetClass() {
// // return targetClass;
// // }
//
// public final <K, V> SetMultimap.Immutable<K, V> of() {
// try {
// return (SetMultimap.Immutable<K, V>) persistentMapOfEmpty.invoke(null);
// } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
// throw new RuntimeException(e);
// }
// }
//
// // @SuppressWarnings("unchecked")
// // public final <K, V> SetMultimap.Immutable<K, V> of(K key, V... values) {
// // try {
// // return (SetMultimap.Immutable<K, V>) persistentMapOfKeyValuePairs.invoke(null, key, values);
// // } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
// // throw new RuntimeException(e);
// // }
// // }
//
// public final <K, V> SetMultimap.Transient<K, V> transientOf() {
// try {
// return (SetMultimap.Transient<K, V>) transientMapOfEmpty.invoke(null);
// } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
// throw new RuntimeException(e);
// }
// }
//
// // @SuppressWarnings("unchecked")
// // public final <K, V> SetMultimap.Transient<K, V> transientOf(K key, V... values) {
// // try {
// // return (SetMultimap.Transient<K, V>) transientMapOfKeyValuePairs.invoke(null, key, values);
// // } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
// // e.printStackTrace();
// // throw new RuntimeException(e);
// // }
// // }
//
// }
//
// Path: src/main/java/io/usethesource/criterion/api/JmhSetMultimap.java
// public interface JmhSetMultimap extends JmhValue { // Iterable<JmhValue>
//
// boolean isEmpty();
//
// int size();
//
// JmhSetMultimap insert(JmhValue key, JmhValue value);
//
// JmhSetMultimap remove(JmhValue key, JmhValue value);
//
// JmhSetMultimap put(JmhValue key, JmhValue value);
//
// JmhSetMultimap remove(JmhValue key);
//
// boolean containsKey(JmhValue key);
//
// boolean containsValue(JmhValue value);
//
// boolean contains(JmhValue key, JmhValue value);
//
// // JmhValue get(JmhValue key);
// //
// // boolean containsValue(JmhValue value);
//
// Iterator<JmhValue> iterator();
//
// // Iterator<JmhValue> valueIterator();
//
// Iterator<Entry<JmhValue, JmhValue>> entryIterator();
//
// Iterator<Entry<JmhValue, Object>> nativeEntryIterator();
//
// java.util.Set<JmhValue> keySet();
//
// public static interface Builder extends JmhBuilder {
//
// void insert(JmhValue key, JmhValue value);
//
// // void putAll(JmhMap map);
// //
// // void putAll(Map<JmhValue, JmhValue> map);
//
// @Override
// JmhSetMultimap done();
//
// }
//
// }
//
// Path: src/main/java/io/usethesource/criterion/api/JmhValue.java
// @CompilerControl(Mode.DONT_INLINE)
// public interface JmhValue {
//
// /**
// * Removes the JmhValue delegation object to reveal its internal representation.
// *
// * @return internal representation
// */
// Object unwrap();
//
// }
// Path: src/main/java/io/usethesource/criterion/impl/persistent/champ/ChampSetMultimapBuilder.java
import io.usethesource.capsule.SetMultimap;
import io.usethesource.capsule.SetMultimapFactory;
import io.usethesource.criterion.api.JmhSetMultimap;
import io.usethesource.criterion.api.JmhValue;
/**
* Copyright (c) Michael Steindorfer <Centrum Wiskunde & Informatica> and Contributors.
* All rights reserved.
*
* This file is licensed under the BSD 2-Clause License, which accompanies this project
* and is available under https://opensource.org/licenses/BSD-2-Clause.
*/
package io.usethesource.criterion.impl.persistent.champ;
final class ChampSetMultimapBuilder implements JmhSetMultimap.Builder {
protected SetMultimap.Immutable<JmhValue, JmhValue> mapContent;
protected JmhSetMultimap constructedMap;
| ChampSetMultimapBuilder(SetMultimapFactory setMultimapFactory) { |
deepaktwr/BitFrames | bitframe/src/main/java/proj/me/bitframe/shading_one/BindingShadeOne.java | // Path: bitframe/src/main/java/proj/me/bitframe/ImageClickHandler.java
// public interface ImageClickHandler {
// void onImageShadeClick(View view);
// }
| import android.graphics.Bitmap;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import proj.me.bitframe.ImageClickHandler;
import proj.me.bitframe.R; | package proj.me.bitframe.shading_one;
/**
* Created by root on 11/3/16.
*/
public class BindingShadeOne {
private View root;
private String comment;
| // Path: bitframe/src/main/java/proj/me/bitframe/ImageClickHandler.java
// public interface ImageClickHandler {
// void onImageShadeClick(View view);
// }
// Path: bitframe/src/main/java/proj/me/bitframe/shading_one/BindingShadeOne.java
import android.graphics.Bitmap;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import proj.me.bitframe.ImageClickHandler;
import proj.me.bitframe.R;
package proj.me.bitframe.shading_one;
/**
* Created by root on 11/3/16.
*/
public class BindingShadeOne {
private View root;
private String comment;
| View bind(View root, final ImageClickHandler clickHandler) { |
deepaktwr/BitFrames | bitframe/src/main/java/proj/me/bitframe/helper/Utils.java | // Path: bitframe/src/main/java/proj/me/bitframe/exceptions/FrameException.java
// public class FrameException extends Exception{
// public FrameException(String message){
// super(message);
// Utils.logVerbose(message);
// }
//
// public FrameException(String message, Throwable throwable){
// super(message, throwable);
// Utils.logVerbose(message);
// }
//
// public FrameException(Throwable throwable){
// super(throwable);
// String message = throwable.getMessage();
// if(!TextUtils.isEmpty(message)) Utils.logVerbose(message);
// }
// }
| import android.content.Context;
import android.content.res.Resources;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.Build;
import android.text.TextUtils;
import android.util.Log;
import android.util.Patterns;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.MimeTypeMap;
import android.webkit.URLUtil;
import android.widget.ImageView;
import android.widget.Toast;
import com.squareup.picasso.Picasso;
import com.squareup.picasso.RequestCreator;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import proj.me.bitframe.R;
import proj.me.bitframe.exceptions.FrameException;
| //shifting to left as 1, 3, 5.....
finalColor += resultInt << i;
bitLength--;
i+=2;
}
bitLength = 32 - n;
int bits = bitLength * 2;
int val = 1 << (bits - 1);
if((val & finalColor) != 0){ finalColor = finalColor >> bits; return finalColor + 1;}
else return finalColor >> bits;
case 4:
return (colors[0] + colors[1] + colors[2] + colors[3]) >> 2;
case 5:
finalColor = colors[0] + colors[1] + colors[2] + colors[3] + colors[4];
int q = (finalColor >> 1) + (finalColor >> 2);
q = q + (q >> 4);
q = q + (q >> 8);
q = q + (q >> 16);
q = q >> 3;
int r = finalColor - (((q << 2) + q) << 1);
return (q + ((r > 9) ? 1 : 0)) << 1;
case 6:
finalColor = getMixedColor(colors[0]+colors[1]+colors[2]+colors[3], colors[4], colors[5]);
return finalColor >> 1;
}
return finalColor;
}
| // Path: bitframe/src/main/java/proj/me/bitframe/exceptions/FrameException.java
// public class FrameException extends Exception{
// public FrameException(String message){
// super(message);
// Utils.logVerbose(message);
// }
//
// public FrameException(String message, Throwable throwable){
// super(message, throwable);
// Utils.logVerbose(message);
// }
//
// public FrameException(Throwable throwable){
// super(throwable);
// String message = throwable.getMessage();
// if(!TextUtils.isEmpty(message)) Utils.logVerbose(message);
// }
// }
// Path: bitframe/src/main/java/proj/me/bitframe/helper/Utils.java
import android.content.Context;
import android.content.res.Resources;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.Build;
import android.text.TextUtils;
import android.util.Log;
import android.util.Patterns;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.MimeTypeMap;
import android.webkit.URLUtil;
import android.widget.ImageView;
import android.widget.Toast;
import com.squareup.picasso.Picasso;
import com.squareup.picasso.RequestCreator;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import proj.me.bitframe.R;
import proj.me.bitframe.exceptions.FrameException;
//shifting to left as 1, 3, 5.....
finalColor += resultInt << i;
bitLength--;
i+=2;
}
bitLength = 32 - n;
int bits = bitLength * 2;
int val = 1 << (bits - 1);
if((val & finalColor) != 0){ finalColor = finalColor >> bits; return finalColor + 1;}
else return finalColor >> bits;
case 4:
return (colors[0] + colors[1] + colors[2] + colors[3]) >> 2;
case 5:
finalColor = colors[0] + colors[1] + colors[2] + colors[3] + colors[4];
int q = (finalColor >> 1) + (finalColor >> 2);
q = q + (q >> 4);
q = q + (q >> 8);
q = q + (q >> 16);
q = q >> 3;
int r = finalColor - (((q << 2) + q) << 1);
return (q + ((r > 9) ? 1 : 0)) << 1;
case 6:
finalColor = getMixedColor(colors[0]+colors[1]+colors[2]+colors[3], colors[4], colors[5]);
return finalColor >> 1;
}
return finalColor;
}
| public static int getMixedArgbColor(int ... colors) throws FrameException{
|
deepaktwr/BitFrames | bitframe/src/main/java/proj/me/bitframe/BeanHandler.java | // Path: bitframe/src/main/java/proj/me/bitframe/BeanImage.java
// public class BeanImage implements Comparable<BeanImage>, Parcelable {
// String imageLink;
// String imageComment;
// int primaryCount, secondaryCount;
//
// public BeanImage(){}
//
// protected BeanImage(Parcel in) {
// imageLink = in.readString();
// imageComment = in.readString();
// primaryCount = in.readInt();
// secondaryCount = in.readInt();
// }
//
// public static final Creator<BeanImage> CREATOR = new Creator<BeanImage>() {
// @Override
// public BeanImage createFromParcel(Parcel in) {
// return new BeanImage(in);
// }
//
// @Override
// public BeanImage[] newArray(int size) {
// return new BeanImage[size];
// }
// };
//
//
// public String getImageLink() {
// return imageLink;
// }
//
// public void setImageLink(String imageLink) {
// this.imageLink = imageLink;
// }
//
// public String getImageComment() {
// return imageComment;
// }
//
// public void setImageComment(String imageComment) {
// this.imageComment = imageComment;
// }
//
// public int getPrimaryCount() {
// return primaryCount;
// }
//
// public void setPrimaryCount(int primaryCount) {
// this.primaryCount = primaryCount;
// }
//
// public int getSecondaryCount() {
// return secondaryCount;
// }
//
// public void setSecondaryCount(int secondaryCount) {
// this.secondaryCount = secondaryCount;
// }
//
// @Override
// public int compareTo(BeanImage another) {
// /*//if in right order then <= 0
// //else need to interchange so > 0
// if(primaryCount == another.getPrimaryCount() && secondaryCount == another.getSecondaryCount()) return 0;
// else if(primaryCount < another.getPrimaryCount()) return 1;//need to interchange a/c to our requirement
// else if(primaryCount > another.getPrimaryCount()) return -1;//are in right order a/c to our requirement
// else if(secondaryCount < another.getSecondaryCount()) return 1;
// else if(secondaryCount > another.getSecondaryCount()) return -1;
// return 1;*/
//
// int first = Math.max(primaryCount + ImageShading.SORT_DIFFERENCE_THRESHOLD, secondaryCount);
// int second = Math.max(another.getPrimaryCount() + ImageShading.SORT_DIFFERENCE_THRESHOLD, another.getSecondaryCount());
//
// return second - first;
// }
//
//
// @Override
// public int describeContents() {
// return 0;
// }
//
// @Override
// public void writeToParcel(Parcel dest, int flags) {
// dest.writeString(imageLink);
// dest.writeString(imageComment);
// dest.writeInt(primaryCount);
// dest.writeInt(secondaryCount);
// }
// }
| import android.graphics.Bitmap;
import proj.me.bitframe.BeanImage; | package proj.me.bitframe;
/**
* Created by root on 16/9/16.
*/
class BeanHandler {
private Bitmap bitmap; | // Path: bitframe/src/main/java/proj/me/bitframe/BeanImage.java
// public class BeanImage implements Comparable<BeanImage>, Parcelable {
// String imageLink;
// String imageComment;
// int primaryCount, secondaryCount;
//
// public BeanImage(){}
//
// protected BeanImage(Parcel in) {
// imageLink = in.readString();
// imageComment = in.readString();
// primaryCount = in.readInt();
// secondaryCount = in.readInt();
// }
//
// public static final Creator<BeanImage> CREATOR = new Creator<BeanImage>() {
// @Override
// public BeanImage createFromParcel(Parcel in) {
// return new BeanImage(in);
// }
//
// @Override
// public BeanImage[] newArray(int size) {
// return new BeanImage[size];
// }
// };
//
//
// public String getImageLink() {
// return imageLink;
// }
//
// public void setImageLink(String imageLink) {
// this.imageLink = imageLink;
// }
//
// public String getImageComment() {
// return imageComment;
// }
//
// public void setImageComment(String imageComment) {
// this.imageComment = imageComment;
// }
//
// public int getPrimaryCount() {
// return primaryCount;
// }
//
// public void setPrimaryCount(int primaryCount) {
// this.primaryCount = primaryCount;
// }
//
// public int getSecondaryCount() {
// return secondaryCount;
// }
//
// public void setSecondaryCount(int secondaryCount) {
// this.secondaryCount = secondaryCount;
// }
//
// @Override
// public int compareTo(BeanImage another) {
// /*//if in right order then <= 0
// //else need to interchange so > 0
// if(primaryCount == another.getPrimaryCount() && secondaryCount == another.getSecondaryCount()) return 0;
// else if(primaryCount < another.getPrimaryCount()) return 1;//need to interchange a/c to our requirement
// else if(primaryCount > another.getPrimaryCount()) return -1;//are in right order a/c to our requirement
// else if(secondaryCount < another.getSecondaryCount()) return 1;
// else if(secondaryCount > another.getSecondaryCount()) return -1;
// return 1;*/
//
// int first = Math.max(primaryCount + ImageShading.SORT_DIFFERENCE_THRESHOLD, secondaryCount);
// int second = Math.max(another.getPrimaryCount() + ImageShading.SORT_DIFFERENCE_THRESHOLD, another.getSecondaryCount());
//
// return second - first;
// }
//
//
// @Override
// public int describeContents() {
// return 0;
// }
//
// @Override
// public void writeToParcel(Parcel dest, int flags) {
// dest.writeString(imageLink);
// dest.writeString(imageComment);
// dest.writeInt(primaryCount);
// dest.writeInt(secondaryCount);
// }
// }
// Path: bitframe/src/main/java/proj/me/bitframe/BeanHandler.java
import android.graphics.Bitmap;
import proj.me.bitframe.BeanImage;
package proj.me.bitframe;
/**
* Created by root on 16/9/16.
*/
class BeanHandler {
private Bitmap bitmap; | private BeanImage beanImage; |
deepaktwr/BitFrames | app/src/main/java/proj/me/bitframedemo/network/RetrofitImpl.java | // Path: app/src/main/java/proj/me/bitframedemo/beans/NextBundle.java
// @JsonInclude(JsonInclude.Include.NON_NULL)
// @JsonPropertyOrder({
// "status",
// "message",
// "bundle_id"
// })
// public class NextBundle implements Parcelable{
//
// @JsonProperty("status")
// private int status;
// @JsonProperty("message")
// private String message;
// @JsonProperty("bundle_id")
// private int bundleId;
//
// public NextBundle(){}
// protected NextBundle(Parcel in) {
// status = in.readInt();
// message = in.readString();
// bundleId = in.readInt();
// }
//
// public static final Creator<NextBundle> CREATOR = new Creator<NextBundle>() {
// @Override
// public NextBundle createFromParcel(Parcel in) {
// return new NextBundle(in);
// }
//
// @Override
// public NextBundle[] newArray(int size) {
// return new NextBundle[size];
// }
// };
//
// /**
// * @return The status
// */
// @JsonProperty("status")
// public int getStatus() {
// return status;
// }
//
// /**
// * @param status The status
// */
// @JsonProperty("status")
// public void setStatus(int status) {
// this.status = status;
// }
//
// /**
// * @return The message
// */
// @JsonProperty("message")
// public String getMessage() {
// return message;
// }
//
// /**
// * @param message The message
// */
// @JsonProperty("message")
// public void setMessage(String message) {
// this.message = message;
// }
//
// /**
// * @return The bundleId
// */
// @JsonProperty("bundle_id")
// public int getBundleId() {
// return bundleId;
// }
//
// /**
// * @param bundleId The bundle_id
// */
// @JsonProperty("bundle_id")
// public void setBundleId(int bundleId) {
// this.bundleId = bundleId;
// }
//
// @Override
// public int describeContents() {
// return 0;
// }
//
// @Override
// public void writeToParcel(Parcel dest, int flags) {
// dest.writeInt(status);
// dest.writeString(message);
// dest.writeInt(bundleId);
// }
// }
| import proj.me.bitframedemo.beans.NextBundle;
import retrofit2.Call;
import retrofit2.http.GET;
import retrofit2.http.Query; | package proj.me.bitframedemo.network;
/**
* Created by root on 17/9/16.
*/
public interface RetrofitImpl {
@GET("getNextBundle") | // Path: app/src/main/java/proj/me/bitframedemo/beans/NextBundle.java
// @JsonInclude(JsonInclude.Include.NON_NULL)
// @JsonPropertyOrder({
// "status",
// "message",
// "bundle_id"
// })
// public class NextBundle implements Parcelable{
//
// @JsonProperty("status")
// private int status;
// @JsonProperty("message")
// private String message;
// @JsonProperty("bundle_id")
// private int bundleId;
//
// public NextBundle(){}
// protected NextBundle(Parcel in) {
// status = in.readInt();
// message = in.readString();
// bundleId = in.readInt();
// }
//
// public static final Creator<NextBundle> CREATOR = new Creator<NextBundle>() {
// @Override
// public NextBundle createFromParcel(Parcel in) {
// return new NextBundle(in);
// }
//
// @Override
// public NextBundle[] newArray(int size) {
// return new NextBundle[size];
// }
// };
//
// /**
// * @return The status
// */
// @JsonProperty("status")
// public int getStatus() {
// return status;
// }
//
// /**
// * @param status The status
// */
// @JsonProperty("status")
// public void setStatus(int status) {
// this.status = status;
// }
//
// /**
// * @return The message
// */
// @JsonProperty("message")
// public String getMessage() {
// return message;
// }
//
// /**
// * @param message The message
// */
// @JsonProperty("message")
// public void setMessage(String message) {
// this.message = message;
// }
//
// /**
// * @return The bundleId
// */
// @JsonProperty("bundle_id")
// public int getBundleId() {
// return bundleId;
// }
//
// /**
// * @param bundleId The bundle_id
// */
// @JsonProperty("bundle_id")
// public void setBundleId(int bundleId) {
// this.bundleId = bundleId;
// }
//
// @Override
// public int describeContents() {
// return 0;
// }
//
// @Override
// public void writeToParcel(Parcel dest, int flags) {
// dest.writeInt(status);
// dest.writeString(message);
// dest.writeInt(bundleId);
// }
// }
// Path: app/src/main/java/proj/me/bitframedemo/network/RetrofitImpl.java
import proj.me.bitframedemo.beans.NextBundle;
import retrofit2.Call;
import retrofit2.http.GET;
import retrofit2.http.Query;
package proj.me.bitframedemo.network;
/**
* Created by root on 17/9/16.
*/
public interface RetrofitImpl {
@GET("getNextBundle") | Call<NextBundle> getNextBundle(@Query("device_id") String deviceId, @Query("request_id") int requestId); |
deepaktwr/BitFrames | bitframe/src/test/java/proj/me/bitframe/MultiDimensionModel.java | // Path: bitframe/src/main/java/proj/me/bitframe/dimentions/ImageOrder.java
// public enum ImageOrder {
// FIRST,
// SECOND,
// THIRD,
// FOURTH
// }
//
// Path: bitframe/src/main/java/proj/me/bitframe/dimentions/LayoutType.java
// public enum LayoutType {
// PARALLEL_HORZ,
// PARALLEL_VERT,
// HORZ,
// VERT,
// IDENTICAL_VARY_WIDTH,
// IDENTICAL_VARY_HEIGHT,
// VERT_HORZ,
// HORZ_VERT,
// VERT_DOUBLE,
// HORZ_DOUBLE
// }
| import proj.me.bitframe.dimentions.ImageOrder;
import proj.me.bitframe.dimentions.LayoutType; | package proj.me.bitframe;
/**
* Created by root on 29/9/16.
*/
public class MultiDimensionModel {
public ImageOrder[] imageOrders; | // Path: bitframe/src/main/java/proj/me/bitframe/dimentions/ImageOrder.java
// public enum ImageOrder {
// FIRST,
// SECOND,
// THIRD,
// FOURTH
// }
//
// Path: bitframe/src/main/java/proj/me/bitframe/dimentions/LayoutType.java
// public enum LayoutType {
// PARALLEL_HORZ,
// PARALLEL_VERT,
// HORZ,
// VERT,
// IDENTICAL_VARY_WIDTH,
// IDENTICAL_VARY_HEIGHT,
// VERT_HORZ,
// HORZ_VERT,
// VERT_DOUBLE,
// HORZ_DOUBLE
// }
// Path: bitframe/src/test/java/proj/me/bitframe/MultiDimensionModel.java
import proj.me.bitframe.dimentions.ImageOrder;
import proj.me.bitframe.dimentions.LayoutType;
package proj.me.bitframe;
/**
* Created by root on 29/9/16.
*/
public class MultiDimensionModel {
public ImageOrder[] imageOrders; | public LayoutType layoutType; |
deepaktwr/BitFrames | bitframe/src/main/java/proj/me/bitframe/shading_three/BindingShadeThree.java | // Path: bitframe/src/main/java/proj/me/bitframe/ImageClickHandler.java
// public interface ImageClickHandler {
// void onImageShadeClick(View view);
// }
| import android.graphics.Bitmap;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import proj.me.bitframe.ImageClickHandler;
import proj.me.bitframe.R; | package proj.me.bitframe.shading_three;
/**
* Created by root on 16/3/16.
*/
public class BindingShadeThree {
private static final String TRIPLE_IMG1_CONTAINER = "triple_img1_container";
private static final String TRIPLE_IMG2_CONTAINER = "triple_img2_container";
private static final String TRIPLE_IMG3_CONTAINER = "triple_img3_container";
private View root;
private int firstImageBgColor;
private String firstComment;
private int secondImageBgColor;
private String secondComment;
private int thirdImageBgColor;
private String thirdComment;
| // Path: bitframe/src/main/java/proj/me/bitframe/ImageClickHandler.java
// public interface ImageClickHandler {
// void onImageShadeClick(View view);
// }
// Path: bitframe/src/main/java/proj/me/bitframe/shading_three/BindingShadeThree.java
import android.graphics.Bitmap;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import proj.me.bitframe.ImageClickHandler;
import proj.me.bitframe.R;
package proj.me.bitframe.shading_three;
/**
* Created by root on 16/3/16.
*/
public class BindingShadeThree {
private static final String TRIPLE_IMG1_CONTAINER = "triple_img1_container";
private static final String TRIPLE_IMG2_CONTAINER = "triple_img2_container";
private static final String TRIPLE_IMG3_CONTAINER = "triple_img3_container";
private View root;
private int firstImageBgColor;
private String firstComment;
private int secondImageBgColor;
private String secondComment;
private int thirdImageBgColor;
private String thirdComment;
| View bind(View root, final ImageClickHandler clickHandler) { |
deepaktwr/BitFrames | app/src/main/java/proj/me/bitframedemo/network/RetrofitClient.java | // Path: app/src/main/java/proj/me/bitframedemo/beans/BaseResponse.java
// @JsonInclude(JsonInclude.Include.NON_NULL)
// @JsonPropertyOrder({
// "status",
// "message"
// })
// public class BaseResponse {
//
// @JsonProperty("status")
// private int status;
// @JsonProperty("message")
// private String message;
//
// /**
// * @return The status
// */
// @JsonProperty("status")
// public int getStatus() {
// return status;
// }
//
// /**
// * @param status The status
// */
// @JsonProperty("status")
// public void setStatus(int status) {
// this.status = status;
// }
//
// /**
// * @return The message
// */
// @JsonProperty("message")
// public String getMessage() {
// return message;
// }
//
// /**
// * @param message The message
// */
// @JsonProperty("message")
// public void setMessage(String message) {
// this.message = message;
// }
// }
| import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import okhttp3.OkHttpClient;
import okhttp3.ResponseBody;
import proj.me.bitframedemo.beans.BaseResponse;
import retrofit2.Converter;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.jackson.JacksonConverterFactory; | retrofit = new Retrofit.Builder()
.baseUrl("http://frame-node12345js.rhcloud.com/")
.addConverterFactory(JacksonConverterFactory.create(objectMapper))
.client(okHttpClient)
.build();
}
public static RetrofitClient createClient(){
if(retrofitClient != null) return retrofitClient;
return retrofitClient = new RetrofitClient<>();
}
public T getRetrofitImpl(Class<T> classObj, int classId){
if(implObject == null) implObject = new HashMap<>();
else if(implObject.containsKey(classId)) return implObject.get(classId);
T obj = retrofit.create(classObj);
implObject.put(classId, obj);
return obj;
}
public <V> String getJsonObject(V object){
String jsonObj = null;
try {
jsonObj = objectMapper.writeValueAsString(object);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
return jsonObj;
}
| // Path: app/src/main/java/proj/me/bitframedemo/beans/BaseResponse.java
// @JsonInclude(JsonInclude.Include.NON_NULL)
// @JsonPropertyOrder({
// "status",
// "message"
// })
// public class BaseResponse {
//
// @JsonProperty("status")
// private int status;
// @JsonProperty("message")
// private String message;
//
// /**
// * @return The status
// */
// @JsonProperty("status")
// public int getStatus() {
// return status;
// }
//
// /**
// * @param status The status
// */
// @JsonProperty("status")
// public void setStatus(int status) {
// this.status = status;
// }
//
// /**
// * @return The message
// */
// @JsonProperty("message")
// public String getMessage() {
// return message;
// }
//
// /**
// * @param message The message
// */
// @JsonProperty("message")
// public void setMessage(String message) {
// this.message = message;
// }
// }
// Path: app/src/main/java/proj/me/bitframedemo/network/RetrofitClient.java
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import okhttp3.OkHttpClient;
import okhttp3.ResponseBody;
import proj.me.bitframedemo.beans.BaseResponse;
import retrofit2.Converter;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.jackson.JacksonConverterFactory;
retrofit = new Retrofit.Builder()
.baseUrl("http://frame-node12345js.rhcloud.com/")
.addConverterFactory(JacksonConverterFactory.create(objectMapper))
.client(okHttpClient)
.build();
}
public static RetrofitClient createClient(){
if(retrofitClient != null) return retrofitClient;
return retrofitClient = new RetrofitClient<>();
}
public T getRetrofitImpl(Class<T> classObj, int classId){
if(implObject == null) implObject = new HashMap<>();
else if(implObject.containsKey(classId)) return implObject.get(classId);
T obj = retrofit.create(classObj);
implObject.put(classId, obj);
return obj;
}
public <V> String getJsonObject(V object){
String jsonObj = null;
try {
jsonObj = objectMapper.writeValueAsString(object);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
return jsonObj;
}
| public <V> V getErrorRespose(Class<V> classObj, Response<BaseResponse> response) throws IOException { |
deepaktwr/BitFrames | bitframe/src/main/java/proj/me/bitframe/shading_two/BindingShadeTwo.java | // Path: bitframe/src/main/java/proj/me/bitframe/ImageClickHandler.java
// public interface ImageClickHandler {
// void onImageShadeClick(View view);
// }
| import android.graphics.Bitmap;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import proj.me.bitframe.ImageClickHandler;
import proj.me.bitframe.R; | package proj.me.bitframe.shading_two;
/**
* Created by root on 14/3/16.
*/
public class BindingShadeTwo {
private static final String DOUBLE_IMG1_CONTAINER = "double_img1_container";
private static final String DOUBLE_IMG2_CONTAINER = "double_img2_container";
private View root;
private String firstComment;
private String secondComment;
private int firstImageBgColor;
private int secondImageBgColor;
private boolean addVisibility;
private boolean addAsCounter;
| // Path: bitframe/src/main/java/proj/me/bitframe/ImageClickHandler.java
// public interface ImageClickHandler {
// void onImageShadeClick(View view);
// }
// Path: bitframe/src/main/java/proj/me/bitframe/shading_two/BindingShadeTwo.java
import android.graphics.Bitmap;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import proj.me.bitframe.ImageClickHandler;
import proj.me.bitframe.R;
package proj.me.bitframe.shading_two;
/**
* Created by root on 14/3/16.
*/
public class BindingShadeTwo {
private static final String DOUBLE_IMG1_CONTAINER = "double_img1_container";
private static final String DOUBLE_IMG2_CONTAINER = "double_img2_container";
private View root;
private String firstComment;
private String secondComment;
private int firstImageBgColor;
private int secondImageBgColor;
private boolean addVisibility;
private boolean addAsCounter;
| View bind(View root, final ImageClickHandler clickHandler) { |
deepaktwr/BitFrames | app/src/main/java/proj/me/bitframedemo/beans/FrameBean.java | // Path: bitframe/src/main/java/proj/me/bitframe/BeanBitFrame.java
// public class BeanBitFrame extends BeanImage{
// float width, height;
// int vibrantColor, mutedColor;
//
// boolean isLoaded;
//
// boolean hasGreaterVibrantPopulation;
// public BeanBitFrame(){
// super();
// }
//
// protected BeanBitFrame(Parcel in) {
// super(in);
// width = in.readFloat();
// height = in.readFloat();
// vibrantColor = in.readInt();
// mutedColor = in.readInt();
// isLoaded = in.readByte() != 0;
// hasGreaterVibrantPopulation = in.readByte() != 0;
// }
//
// @Override
// public void writeToParcel(Parcel dest, int flags) {
// super.writeToParcel(dest, flags);
// dest.writeFloat(width);
// dest.writeFloat(height);
// dest.writeInt(vibrantColor);
// dest.writeInt(mutedColor);
// dest.writeByte((byte) (isLoaded ? 1 : 0));
// dest.writeByte((byte) (hasGreaterVibrantPopulation ? 1 : 0));
// }
//
// @Override
// public int describeContents() {
// return 0;
// }
//
// public static final Creator<BeanBitFrame> CREATOR = new Creator<BeanBitFrame>() {
// @Override
// public BeanBitFrame createFromParcel(Parcel in) {
// return new BeanBitFrame(in);
// }
//
// @Override
// public BeanBitFrame[] newArray(int size) {
// return new BeanBitFrame[size];
// }
// };
// public boolean isHasGreaterVibrantPopulation() {
// return hasGreaterVibrantPopulation;
// }
//
// public void setHasGreaterVibrantPopulation(boolean hasGreaterVibrantPopulation) {
// this.hasGreaterVibrantPopulation = hasGreaterVibrantPopulation;
// }
//
// public boolean isLoaded() {
// return isLoaded;
// }
//
// public void setLoaded(boolean loaded) {
// isLoaded = loaded;
// }
//
// public float getWidth() {
// return width;
// }
//
// public void setWidth(float width) {
// this.width = width;
// }
//
// public float getHeight() {
// return height;
// }
//
// public void setHeight(float height) {
// this.height = height;
// }
//
// public int getVibrantColor() {
// return vibrantColor;
// }
//
// public void setVibrantColor(int vibrantColor) {
// this.vibrantColor = vibrantColor;
// }
//
// public int getMutedColor() {
// return mutedColor;
// }
//
// public void setMutedColor(int mutedColor) {
// this.mutedColor = mutedColor;
// }
// }
//
// Path: bitframe/src/main/java/proj/me/bitframe/BeanImage.java
// public class BeanImage implements Comparable<BeanImage>, Parcelable {
// String imageLink;
// String imageComment;
// int primaryCount, secondaryCount;
//
// public BeanImage(){}
//
// protected BeanImage(Parcel in) {
// imageLink = in.readString();
// imageComment = in.readString();
// primaryCount = in.readInt();
// secondaryCount = in.readInt();
// }
//
// public static final Creator<BeanImage> CREATOR = new Creator<BeanImage>() {
// @Override
// public BeanImage createFromParcel(Parcel in) {
// return new BeanImage(in);
// }
//
// @Override
// public BeanImage[] newArray(int size) {
// return new BeanImage[size];
// }
// };
//
//
// public String getImageLink() {
// return imageLink;
// }
//
// public void setImageLink(String imageLink) {
// this.imageLink = imageLink;
// }
//
// public String getImageComment() {
// return imageComment;
// }
//
// public void setImageComment(String imageComment) {
// this.imageComment = imageComment;
// }
//
// public int getPrimaryCount() {
// return primaryCount;
// }
//
// public void setPrimaryCount(int primaryCount) {
// this.primaryCount = primaryCount;
// }
//
// public int getSecondaryCount() {
// return secondaryCount;
// }
//
// public void setSecondaryCount(int secondaryCount) {
// this.secondaryCount = secondaryCount;
// }
//
// @Override
// public int compareTo(BeanImage another) {
// /*//if in right order then <= 0
// //else need to interchange so > 0
// if(primaryCount == another.getPrimaryCount() && secondaryCount == another.getSecondaryCount()) return 0;
// else if(primaryCount < another.getPrimaryCount()) return 1;//need to interchange a/c to our requirement
// else if(primaryCount > another.getPrimaryCount()) return -1;//are in right order a/c to our requirement
// else if(secondaryCount < another.getSecondaryCount()) return 1;
// else if(secondaryCount > another.getSecondaryCount()) return -1;
// return 1;*/
//
// int first = Math.max(primaryCount + ImageShading.SORT_DIFFERENCE_THRESHOLD, secondaryCount);
// int second = Math.max(another.getPrimaryCount() + ImageShading.SORT_DIFFERENCE_THRESHOLD, another.getSecondaryCount());
//
// return second - first;
// }
//
//
// @Override
// public int describeContents() {
// return 0;
// }
//
// @Override
// public void writeToParcel(Parcel dest, int flags) {
// dest.writeString(imageLink);
// dest.writeString(imageComment);
// dest.writeInt(primaryCount);
// dest.writeInt(secondaryCount);
// }
// }
| import java.util.List;
import proj.me.bitframe.BeanBitFrame;
import proj.me.bitframe.BeanImage; | package proj.me.bitframedemo.beans;
/**
* Created by root on 20/9/16.
*/
public class FrameBean {
private String title;
private String description; | // Path: bitframe/src/main/java/proj/me/bitframe/BeanBitFrame.java
// public class BeanBitFrame extends BeanImage{
// float width, height;
// int vibrantColor, mutedColor;
//
// boolean isLoaded;
//
// boolean hasGreaterVibrantPopulation;
// public BeanBitFrame(){
// super();
// }
//
// protected BeanBitFrame(Parcel in) {
// super(in);
// width = in.readFloat();
// height = in.readFloat();
// vibrantColor = in.readInt();
// mutedColor = in.readInt();
// isLoaded = in.readByte() != 0;
// hasGreaterVibrantPopulation = in.readByte() != 0;
// }
//
// @Override
// public void writeToParcel(Parcel dest, int flags) {
// super.writeToParcel(dest, flags);
// dest.writeFloat(width);
// dest.writeFloat(height);
// dest.writeInt(vibrantColor);
// dest.writeInt(mutedColor);
// dest.writeByte((byte) (isLoaded ? 1 : 0));
// dest.writeByte((byte) (hasGreaterVibrantPopulation ? 1 : 0));
// }
//
// @Override
// public int describeContents() {
// return 0;
// }
//
// public static final Creator<BeanBitFrame> CREATOR = new Creator<BeanBitFrame>() {
// @Override
// public BeanBitFrame createFromParcel(Parcel in) {
// return new BeanBitFrame(in);
// }
//
// @Override
// public BeanBitFrame[] newArray(int size) {
// return new BeanBitFrame[size];
// }
// };
// public boolean isHasGreaterVibrantPopulation() {
// return hasGreaterVibrantPopulation;
// }
//
// public void setHasGreaterVibrantPopulation(boolean hasGreaterVibrantPopulation) {
// this.hasGreaterVibrantPopulation = hasGreaterVibrantPopulation;
// }
//
// public boolean isLoaded() {
// return isLoaded;
// }
//
// public void setLoaded(boolean loaded) {
// isLoaded = loaded;
// }
//
// public float getWidth() {
// return width;
// }
//
// public void setWidth(float width) {
// this.width = width;
// }
//
// public float getHeight() {
// return height;
// }
//
// public void setHeight(float height) {
// this.height = height;
// }
//
// public int getVibrantColor() {
// return vibrantColor;
// }
//
// public void setVibrantColor(int vibrantColor) {
// this.vibrantColor = vibrantColor;
// }
//
// public int getMutedColor() {
// return mutedColor;
// }
//
// public void setMutedColor(int mutedColor) {
// this.mutedColor = mutedColor;
// }
// }
//
// Path: bitframe/src/main/java/proj/me/bitframe/BeanImage.java
// public class BeanImage implements Comparable<BeanImage>, Parcelable {
// String imageLink;
// String imageComment;
// int primaryCount, secondaryCount;
//
// public BeanImage(){}
//
// protected BeanImage(Parcel in) {
// imageLink = in.readString();
// imageComment = in.readString();
// primaryCount = in.readInt();
// secondaryCount = in.readInt();
// }
//
// public static final Creator<BeanImage> CREATOR = new Creator<BeanImage>() {
// @Override
// public BeanImage createFromParcel(Parcel in) {
// return new BeanImage(in);
// }
//
// @Override
// public BeanImage[] newArray(int size) {
// return new BeanImage[size];
// }
// };
//
//
// public String getImageLink() {
// return imageLink;
// }
//
// public void setImageLink(String imageLink) {
// this.imageLink = imageLink;
// }
//
// public String getImageComment() {
// return imageComment;
// }
//
// public void setImageComment(String imageComment) {
// this.imageComment = imageComment;
// }
//
// public int getPrimaryCount() {
// return primaryCount;
// }
//
// public void setPrimaryCount(int primaryCount) {
// this.primaryCount = primaryCount;
// }
//
// public int getSecondaryCount() {
// return secondaryCount;
// }
//
// public void setSecondaryCount(int secondaryCount) {
// this.secondaryCount = secondaryCount;
// }
//
// @Override
// public int compareTo(BeanImage another) {
// /*//if in right order then <= 0
// //else need to interchange so > 0
// if(primaryCount == another.getPrimaryCount() && secondaryCount == another.getSecondaryCount()) return 0;
// else if(primaryCount < another.getPrimaryCount()) return 1;//need to interchange a/c to our requirement
// else if(primaryCount > another.getPrimaryCount()) return -1;//are in right order a/c to our requirement
// else if(secondaryCount < another.getSecondaryCount()) return 1;
// else if(secondaryCount > another.getSecondaryCount()) return -1;
// return 1;*/
//
// int first = Math.max(primaryCount + ImageShading.SORT_DIFFERENCE_THRESHOLD, secondaryCount);
// int second = Math.max(another.getPrimaryCount() + ImageShading.SORT_DIFFERENCE_THRESHOLD, another.getSecondaryCount());
//
// return second - first;
// }
//
//
// @Override
// public int describeContents() {
// return 0;
// }
//
// @Override
// public void writeToParcel(Parcel dest, int flags) {
// dest.writeString(imageLink);
// dest.writeString(imageComment);
// dest.writeInt(primaryCount);
// dest.writeInt(secondaryCount);
// }
// }
// Path: app/src/main/java/proj/me/bitframedemo/beans/FrameBean.java
import java.util.List;
import proj.me.bitframe.BeanBitFrame;
import proj.me.bitframe.BeanImage;
package proj.me.bitframedemo.beans;
/**
* Created by root on 20/9/16.
*/
public class FrameBean {
private String title;
private String description; | private List<BeanImage> beanBitFrameList; |
deepaktwr/BitFrames | app/src/main/java/proj/me/bitframedemo/network/UploadImpl.java | // Path: app/src/main/java/proj/me/bitframedemo/beans/BaseResponse.java
// @JsonInclude(JsonInclude.Include.NON_NULL)
// @JsonPropertyOrder({
// "status",
// "message"
// })
// public class BaseResponse {
//
// @JsonProperty("status")
// private int status;
// @JsonProperty("message")
// private String message;
//
// /**
// * @return The status
// */
// @JsonProperty("status")
// public int getStatus() {
// return status;
// }
//
// /**
// * @param status The status
// */
// @JsonProperty("status")
// public void setStatus(int status) {
// this.status = status;
// }
//
// /**
// * @return The message
// */
// @JsonProperty("message")
// public String getMessage() {
// return message;
// }
//
// /**
// * @param message The message
// */
// @JsonProperty("message")
// public void setMessage(String message) {
// this.message = message;
// }
// }
//
// Path: app/src/main/java/proj/me/bitframedemo/beans/UploadRequest.java
// @JsonInclude(JsonInclude.Include.NON_NULL)
// @JsonPropertyOrder({
// "device_id",
// "request_id",
// "bundle_id",
// "bundle"
// })
// public class UploadRequest {
// @JsonProperty("device_id")
// private String deviceId;
// @JsonProperty("request_id")
// private int requestId;
// @JsonProperty("bundle_id")
// private int bundleId;
// @JsonProperty("bundle")
// private Bundle bundle;
//
// /**
// *
// * @return
// * The deviceId
// */
// @JsonProperty("device_id")
// public String getDeviceId() {
// return deviceId;
// }
//
// /**
// *
// * @param deviceId
// * The device_id
// */
// @JsonProperty("device_id")
// public void setDeviceId(String deviceId) {
// this.deviceId = deviceId;
// }
//
// /**
// *
// * @return
// * The requestId
// */
// @JsonProperty("request_id")
// public int getRequestId() {
// return requestId;
// }
//
// /**
// *
// * @param requestId
// * The request_id
// */
// @JsonProperty("request_id")
// public void setRequestId(int requestId) {
// this.requestId = requestId;
// }
//
// /**
// *
// * @return
// * The bundleId
// */
// @JsonProperty("bundle_id")
// public int getBundleId() {
// return bundleId;
// }
//
// /**
// *
// * @param bundleId
// * The bundle_id
// */
// @JsonProperty("bundle_id")
// public void setBundleId(int bundleId) {
// this.bundleId = bundleId;
// }
//
// /**
// *
// * @return
// * The bundle
// */
// @JsonProperty("bundle")
// public Bundle getBundle() {
// return bundle;
// }
//
// /**
// *
// * @param bundle
// * The bundle
// */
// @JsonProperty("bundle")
// public void setBundle(Bundle bundle) {
// this.bundle = bundle;
// }
// }
| import okhttp3.RequestBody;
import proj.me.bitframedemo.beans.BaseResponse;
import proj.me.bitframedemo.beans.UploadRequest;
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.Multipart;
import retrofit2.http.POST;
import retrofit2.http.Part; | package proj.me.bitframedemo.network;
/**
* Created by root on 18/9/16.
*/
public interface UploadImpl {
@Multipart
@POST("uploadBundle") | // Path: app/src/main/java/proj/me/bitframedemo/beans/BaseResponse.java
// @JsonInclude(JsonInclude.Include.NON_NULL)
// @JsonPropertyOrder({
// "status",
// "message"
// })
// public class BaseResponse {
//
// @JsonProperty("status")
// private int status;
// @JsonProperty("message")
// private String message;
//
// /**
// * @return The status
// */
// @JsonProperty("status")
// public int getStatus() {
// return status;
// }
//
// /**
// * @param status The status
// */
// @JsonProperty("status")
// public void setStatus(int status) {
// this.status = status;
// }
//
// /**
// * @return The message
// */
// @JsonProperty("message")
// public String getMessage() {
// return message;
// }
//
// /**
// * @param message The message
// */
// @JsonProperty("message")
// public void setMessage(String message) {
// this.message = message;
// }
// }
//
// Path: app/src/main/java/proj/me/bitframedemo/beans/UploadRequest.java
// @JsonInclude(JsonInclude.Include.NON_NULL)
// @JsonPropertyOrder({
// "device_id",
// "request_id",
// "bundle_id",
// "bundle"
// })
// public class UploadRequest {
// @JsonProperty("device_id")
// private String deviceId;
// @JsonProperty("request_id")
// private int requestId;
// @JsonProperty("bundle_id")
// private int bundleId;
// @JsonProperty("bundle")
// private Bundle bundle;
//
// /**
// *
// * @return
// * The deviceId
// */
// @JsonProperty("device_id")
// public String getDeviceId() {
// return deviceId;
// }
//
// /**
// *
// * @param deviceId
// * The device_id
// */
// @JsonProperty("device_id")
// public void setDeviceId(String deviceId) {
// this.deviceId = deviceId;
// }
//
// /**
// *
// * @return
// * The requestId
// */
// @JsonProperty("request_id")
// public int getRequestId() {
// return requestId;
// }
//
// /**
// *
// * @param requestId
// * The request_id
// */
// @JsonProperty("request_id")
// public void setRequestId(int requestId) {
// this.requestId = requestId;
// }
//
// /**
// *
// * @return
// * The bundleId
// */
// @JsonProperty("bundle_id")
// public int getBundleId() {
// return bundleId;
// }
//
// /**
// *
// * @param bundleId
// * The bundle_id
// */
// @JsonProperty("bundle_id")
// public void setBundleId(int bundleId) {
// this.bundleId = bundleId;
// }
//
// /**
// *
// * @return
// * The bundle
// */
// @JsonProperty("bundle")
// public Bundle getBundle() {
// return bundle;
// }
//
// /**
// *
// * @param bundle
// * The bundle
// */
// @JsonProperty("bundle")
// public void setBundle(Bundle bundle) {
// this.bundle = bundle;
// }
// }
// Path: app/src/main/java/proj/me/bitframedemo/network/UploadImpl.java
import okhttp3.RequestBody;
import proj.me.bitframedemo.beans.BaseResponse;
import proj.me.bitframedemo.beans.UploadRequest;
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.Multipart;
import retrofit2.http.POST;
import retrofit2.http.Part;
package proj.me.bitframedemo.network;
/**
* Created by root on 18/9/16.
*/
public interface UploadImpl {
@Multipart
@POST("uploadBundle") | Call<BaseResponse> uploadImage(@Part("file\"; fileName=\"myFile.png\" ")RequestBody requestBodyFile, @Part("image") RequestBody requestBodyJson); |
deepaktwr/BitFrames | app/src/main/java/proj/me/bitframedemo/network/UploadImpl.java | // Path: app/src/main/java/proj/me/bitframedemo/beans/BaseResponse.java
// @JsonInclude(JsonInclude.Include.NON_NULL)
// @JsonPropertyOrder({
// "status",
// "message"
// })
// public class BaseResponse {
//
// @JsonProperty("status")
// private int status;
// @JsonProperty("message")
// private String message;
//
// /**
// * @return The status
// */
// @JsonProperty("status")
// public int getStatus() {
// return status;
// }
//
// /**
// * @param status The status
// */
// @JsonProperty("status")
// public void setStatus(int status) {
// this.status = status;
// }
//
// /**
// * @return The message
// */
// @JsonProperty("message")
// public String getMessage() {
// return message;
// }
//
// /**
// * @param message The message
// */
// @JsonProperty("message")
// public void setMessage(String message) {
// this.message = message;
// }
// }
//
// Path: app/src/main/java/proj/me/bitframedemo/beans/UploadRequest.java
// @JsonInclude(JsonInclude.Include.NON_NULL)
// @JsonPropertyOrder({
// "device_id",
// "request_id",
// "bundle_id",
// "bundle"
// })
// public class UploadRequest {
// @JsonProperty("device_id")
// private String deviceId;
// @JsonProperty("request_id")
// private int requestId;
// @JsonProperty("bundle_id")
// private int bundleId;
// @JsonProperty("bundle")
// private Bundle bundle;
//
// /**
// *
// * @return
// * The deviceId
// */
// @JsonProperty("device_id")
// public String getDeviceId() {
// return deviceId;
// }
//
// /**
// *
// * @param deviceId
// * The device_id
// */
// @JsonProperty("device_id")
// public void setDeviceId(String deviceId) {
// this.deviceId = deviceId;
// }
//
// /**
// *
// * @return
// * The requestId
// */
// @JsonProperty("request_id")
// public int getRequestId() {
// return requestId;
// }
//
// /**
// *
// * @param requestId
// * The request_id
// */
// @JsonProperty("request_id")
// public void setRequestId(int requestId) {
// this.requestId = requestId;
// }
//
// /**
// *
// * @return
// * The bundleId
// */
// @JsonProperty("bundle_id")
// public int getBundleId() {
// return bundleId;
// }
//
// /**
// *
// * @param bundleId
// * The bundle_id
// */
// @JsonProperty("bundle_id")
// public void setBundleId(int bundleId) {
// this.bundleId = bundleId;
// }
//
// /**
// *
// * @return
// * The bundle
// */
// @JsonProperty("bundle")
// public Bundle getBundle() {
// return bundle;
// }
//
// /**
// *
// * @param bundle
// * The bundle
// */
// @JsonProperty("bundle")
// public void setBundle(Bundle bundle) {
// this.bundle = bundle;
// }
// }
| import okhttp3.RequestBody;
import proj.me.bitframedemo.beans.BaseResponse;
import proj.me.bitframedemo.beans.UploadRequest;
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.Multipart;
import retrofit2.http.POST;
import retrofit2.http.Part; | package proj.me.bitframedemo.network;
/**
* Created by root on 18/9/16.
*/
public interface UploadImpl {
@Multipart
@POST("uploadBundle")
Call<BaseResponse> uploadImage(@Part("file\"; fileName=\"myFile.png\" ")RequestBody requestBodyFile, @Part("image") RequestBody requestBodyJson);
@POST("postBundle") | // Path: app/src/main/java/proj/me/bitframedemo/beans/BaseResponse.java
// @JsonInclude(JsonInclude.Include.NON_NULL)
// @JsonPropertyOrder({
// "status",
// "message"
// })
// public class BaseResponse {
//
// @JsonProperty("status")
// private int status;
// @JsonProperty("message")
// private String message;
//
// /**
// * @return The status
// */
// @JsonProperty("status")
// public int getStatus() {
// return status;
// }
//
// /**
// * @param status The status
// */
// @JsonProperty("status")
// public void setStatus(int status) {
// this.status = status;
// }
//
// /**
// * @return The message
// */
// @JsonProperty("message")
// public String getMessage() {
// return message;
// }
//
// /**
// * @param message The message
// */
// @JsonProperty("message")
// public void setMessage(String message) {
// this.message = message;
// }
// }
//
// Path: app/src/main/java/proj/me/bitframedemo/beans/UploadRequest.java
// @JsonInclude(JsonInclude.Include.NON_NULL)
// @JsonPropertyOrder({
// "device_id",
// "request_id",
// "bundle_id",
// "bundle"
// })
// public class UploadRequest {
// @JsonProperty("device_id")
// private String deviceId;
// @JsonProperty("request_id")
// private int requestId;
// @JsonProperty("bundle_id")
// private int bundleId;
// @JsonProperty("bundle")
// private Bundle bundle;
//
// /**
// *
// * @return
// * The deviceId
// */
// @JsonProperty("device_id")
// public String getDeviceId() {
// return deviceId;
// }
//
// /**
// *
// * @param deviceId
// * The device_id
// */
// @JsonProperty("device_id")
// public void setDeviceId(String deviceId) {
// this.deviceId = deviceId;
// }
//
// /**
// *
// * @return
// * The requestId
// */
// @JsonProperty("request_id")
// public int getRequestId() {
// return requestId;
// }
//
// /**
// *
// * @param requestId
// * The request_id
// */
// @JsonProperty("request_id")
// public void setRequestId(int requestId) {
// this.requestId = requestId;
// }
//
// /**
// *
// * @return
// * The bundleId
// */
// @JsonProperty("bundle_id")
// public int getBundleId() {
// return bundleId;
// }
//
// /**
// *
// * @param bundleId
// * The bundle_id
// */
// @JsonProperty("bundle_id")
// public void setBundleId(int bundleId) {
// this.bundleId = bundleId;
// }
//
// /**
// *
// * @return
// * The bundle
// */
// @JsonProperty("bundle")
// public Bundle getBundle() {
// return bundle;
// }
//
// /**
// *
// * @param bundle
// * The bundle
// */
// @JsonProperty("bundle")
// public void setBundle(Bundle bundle) {
// this.bundle = bundle;
// }
// }
// Path: app/src/main/java/proj/me/bitframedemo/network/UploadImpl.java
import okhttp3.RequestBody;
import proj.me.bitframedemo.beans.BaseResponse;
import proj.me.bitframedemo.beans.UploadRequest;
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.Multipart;
import retrofit2.http.POST;
import retrofit2.http.Part;
package proj.me.bitframedemo.network;
/**
* Created by root on 18/9/16.
*/
public interface UploadImpl {
@Multipart
@POST("uploadBundle")
Call<BaseResponse> uploadImage(@Part("file\"; fileName=\"myFile.png\" ")RequestBody requestBodyFile, @Part("image") RequestBody requestBodyJson);
@POST("postBundle") | Call<BaseResponse> postBundle(@Body UploadRequest uploadRequest); |
deepaktwr/BitFrames | app/src/main/java/proj/me/bitframedemo/network/DownloadImpl.java | // Path: app/src/main/java/proj/me/bitframedemo/beans/FrameResponse.java
// @JsonInclude(JsonInclude.Include.NON_NULL)
// @JsonPropertyOrder({
// "status",
// "message",
// "bundle"
// })
// public class FrameResponse implements Parcelable{
//
// @JsonProperty("status")
// private int status;
// @JsonProperty("message")
// private String message;
// @JsonProperty("bundle")
// private List<BundleDetail> bundle = new ArrayList<BundleDetail>();
//
// public FrameResponse(){}
//
// protected FrameResponse(Parcel in) {
// status = in.readInt();
// message = in.readString();
// bundle = in.createTypedArrayList(BundleDetail.CREATOR);
// }
//
// public static final Creator<FrameResponse> CREATOR = new Creator<FrameResponse>() {
// @Override
// public FrameResponse createFromParcel(Parcel in) {
// return new FrameResponse(in);
// }
//
// @Override
// public FrameResponse[] newArray(int size) {
// return new FrameResponse[size];
// }
// };
//
// /**
// * @return The status
// */
// @JsonProperty("status")
// public int getStatus() {
// return status;
// }
//
// /**
// * @param status The status
// */
// @JsonProperty("status")
// public void setStatus(int status) {
// this.status = status;
// }
//
// /**
// * @return The message
// */
// @JsonProperty("message")
// public String getMessage() {
// return message;
// }
//
// /**
// * @param message The message
// */
// @JsonProperty("message")
// public void setMessage(String message) {
// this.message = message;
// }
//
// /**
// * @return The bundle
// */
// @JsonProperty("bundle")
// public List<BundleDetail> getBundle() {
// return bundle;
// }
//
// /**
// * @param bundle The bundle
// */
// @JsonProperty("bundle")
// public void setBundle(List<BundleDetail> bundle) {
// this.bundle = bundle;
// }
//
// @Override
// public int describeContents() {
// return 0;
// }
//
// @Override
// public void writeToParcel(Parcel dest, int flags) {
// dest.writeInt(status);
// dest.writeString(message);
// dest.writeTypedList(bundle);
// }
// }
| import proj.me.bitframedemo.beans.FrameResponse;
import retrofit2.Call;
import retrofit2.http.GET;
import retrofit2.http.Query; | package proj.me.bitframedemo.network;
/**
* Created by root on 20/9/16.
*/
public interface DownloadImpl {
@GET("getDeviceBundle") | // Path: app/src/main/java/proj/me/bitframedemo/beans/FrameResponse.java
// @JsonInclude(JsonInclude.Include.NON_NULL)
// @JsonPropertyOrder({
// "status",
// "message",
// "bundle"
// })
// public class FrameResponse implements Parcelable{
//
// @JsonProperty("status")
// private int status;
// @JsonProperty("message")
// private String message;
// @JsonProperty("bundle")
// private List<BundleDetail> bundle = new ArrayList<BundleDetail>();
//
// public FrameResponse(){}
//
// protected FrameResponse(Parcel in) {
// status = in.readInt();
// message = in.readString();
// bundle = in.createTypedArrayList(BundleDetail.CREATOR);
// }
//
// public static final Creator<FrameResponse> CREATOR = new Creator<FrameResponse>() {
// @Override
// public FrameResponse createFromParcel(Parcel in) {
// return new FrameResponse(in);
// }
//
// @Override
// public FrameResponse[] newArray(int size) {
// return new FrameResponse[size];
// }
// };
//
// /**
// * @return The status
// */
// @JsonProperty("status")
// public int getStatus() {
// return status;
// }
//
// /**
// * @param status The status
// */
// @JsonProperty("status")
// public void setStatus(int status) {
// this.status = status;
// }
//
// /**
// * @return The message
// */
// @JsonProperty("message")
// public String getMessage() {
// return message;
// }
//
// /**
// * @param message The message
// */
// @JsonProperty("message")
// public void setMessage(String message) {
// this.message = message;
// }
//
// /**
// * @return The bundle
// */
// @JsonProperty("bundle")
// public List<BundleDetail> getBundle() {
// return bundle;
// }
//
// /**
// * @param bundle The bundle
// */
// @JsonProperty("bundle")
// public void setBundle(List<BundleDetail> bundle) {
// this.bundle = bundle;
// }
//
// @Override
// public int describeContents() {
// return 0;
// }
//
// @Override
// public void writeToParcel(Parcel dest, int flags) {
// dest.writeInt(status);
// dest.writeString(message);
// dest.writeTypedList(bundle);
// }
// }
// Path: app/src/main/java/proj/me/bitframedemo/network/DownloadImpl.java
import proj.me.bitframedemo.beans.FrameResponse;
import retrofit2.Call;
import retrofit2.http.GET;
import retrofit2.http.Query;
package proj.me.bitframedemo.network;
/**
* Created by root on 20/9/16.
*/
public interface DownloadImpl {
@GET("getDeviceBundle") | Call<FrameResponse> getDeviceBundle(@Query("device_id") String deviceId); |
deepaktwr/BitFrames | bitframe/src/main/java/proj/me/bitframe/shading_four/BindingShadeFour.java | // Path: bitframe/src/main/java/proj/me/bitframe/ImageClickHandler.java
// public interface ImageClickHandler {
// void onImageShadeClick(View view);
// }
| import android.graphics.Bitmap;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import proj.me.bitframe.ImageClickHandler;
import proj.me.bitframe.R; | package proj.me.bitframe.shading_four;
/**
* Created by root on 16/3/16.
*/
public class BindingShadeFour {
private static final String MULTIPLE_IMG1_CONTAINER = "multiple_img1_container";
private static final String MULTIPLE_IMG2_CONTAINER = "multiple_img2_container";
private static final String MULTIPLE_IMG3_CONTAINER = "multiple_img3_container";
private static final String MULTIPLE_IMG4_CONTAINER = "multiple_img4_container";
private View root;
private int firstImageBgColor;
private String firstComment;
private int secondImageBgColor;
private String secondComment;
private int thirdImageBgColor;
private String thirdComment;
private int fourthImageBgColor;
private String fourthComment;
| // Path: bitframe/src/main/java/proj/me/bitframe/ImageClickHandler.java
// public interface ImageClickHandler {
// void onImageShadeClick(View view);
// }
// Path: bitframe/src/main/java/proj/me/bitframe/shading_four/BindingShadeFour.java
import android.graphics.Bitmap;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import proj.me.bitframe.ImageClickHandler;
import proj.me.bitframe.R;
package proj.me.bitframe.shading_four;
/**
* Created by root on 16/3/16.
*/
public class BindingShadeFour {
private static final String MULTIPLE_IMG1_CONTAINER = "multiple_img1_container";
private static final String MULTIPLE_IMG2_CONTAINER = "multiple_img2_container";
private static final String MULTIPLE_IMG3_CONTAINER = "multiple_img3_container";
private static final String MULTIPLE_IMG4_CONTAINER = "multiple_img4_container";
private View root;
private int firstImageBgColor;
private String firstComment;
private int secondImageBgColor;
private String secondComment;
private int thirdImageBgColor;
private String thirdComment;
private int fourthImageBgColor;
private String fourthComment;
| View bind(View root, final ImageClickHandler clickHandler) { |
deepaktwr/BitFrames | bitframe/src/main/java/proj/me/bitframe/FrameHandler.java | // Path: bitframe/src/main/java/proj/me/bitframe/exceptions/FrameException.java
// public class FrameException extends Exception{
// public FrameException(String message){
// super(message);
// Utils.logVerbose(message);
// }
//
// public FrameException(String message, Throwable throwable){
// super(message, throwable);
// Utils.logVerbose(message);
// }
//
// public FrameException(Throwable throwable){
// super(throwable);
// String message = throwable.getMessage();
// if(!TextUtils.isEmpty(message)) Utils.logVerbose(message);
// }
// }
| import android.graphics.Bitmap;
import android.os.Handler;
import android.os.Message;
import androidx.palette.graphics.Palette;
import proj.me.bitframe.exceptions.FrameException; | package proj.me.bitframe;
class FrameHandler extends Handler {
ImageResult imageResult;
FrameHandler(ImageResult imageResult) {
this.imageResult = imageResult;
}
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case 1:
final BeanHandler beanHandler = (BeanHandler) msg.obj;
final Bitmap bitmap = beanHandler.getBitmap();
if (imageResult.getCounter() >= imageResult.getFrameModel().getMaxFrameCount()) {
imageResult.updateCounter();
final BeanBitFrame beanBitFrame = new BeanBitFrame();
beanBitFrame.setWidth(bitmap.getWidth());
beanBitFrame.setHeight(bitmap.getHeight());
beanBitFrame.setLoaded(true);
Palette.from(bitmap).generate(new PaletteListener(imageResult, beanBitFrame, beanHandler.getBeanImage(), false));
} else {
boolean doneLoading = imageResult.getCounter() == (imageResult.getFrameModel().getMaxFrameCount()
>= imageResult.getTotalImages() ? imageResult.getTotalImages()
: imageResult.getFrameModel().getMaxFrameCount()) - 1;
imageResult.setDoneLoading(doneLoading);
try {
imageResult.onImageLoaded(true, bitmap, beanHandler.getBeanImage()); | // Path: bitframe/src/main/java/proj/me/bitframe/exceptions/FrameException.java
// public class FrameException extends Exception{
// public FrameException(String message){
// super(message);
// Utils.logVerbose(message);
// }
//
// public FrameException(String message, Throwable throwable){
// super(message, throwable);
// Utils.logVerbose(message);
// }
//
// public FrameException(Throwable throwable){
// super(throwable);
// String message = throwable.getMessage();
// if(!TextUtils.isEmpty(message)) Utils.logVerbose(message);
// }
// }
// Path: bitframe/src/main/java/proj/me/bitframe/FrameHandler.java
import android.graphics.Bitmap;
import android.os.Handler;
import android.os.Message;
import androidx.palette.graphics.Palette;
import proj.me.bitframe.exceptions.FrameException;
package proj.me.bitframe;
class FrameHandler extends Handler {
ImageResult imageResult;
FrameHandler(ImageResult imageResult) {
this.imageResult = imageResult;
}
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case 1:
final BeanHandler beanHandler = (BeanHandler) msg.obj;
final Bitmap bitmap = beanHandler.getBitmap();
if (imageResult.getCounter() >= imageResult.getFrameModel().getMaxFrameCount()) {
imageResult.updateCounter();
final BeanBitFrame beanBitFrame = new BeanBitFrame();
beanBitFrame.setWidth(bitmap.getWidth());
beanBitFrame.setHeight(bitmap.getHeight());
beanBitFrame.setLoaded(true);
Palette.from(bitmap).generate(new PaletteListener(imageResult, beanBitFrame, beanHandler.getBeanImage(), false));
} else {
boolean doneLoading = imageResult.getCounter() == (imageResult.getFrameModel().getMaxFrameCount()
>= imageResult.getTotalImages() ? imageResult.getTotalImages()
: imageResult.getFrameModel().getMaxFrameCount()) - 1;
imageResult.setDoneLoading(doneLoading);
try {
imageResult.onImageLoaded(true, bitmap, beanHandler.getBeanImage()); | } catch (FrameException e) { |
deepaktwr/BitFrames | bitframe/src/main/java/proj/me/bitframe/FrameModel.java | // Path: bitframe/src/main/java/proj/me/bitframe/helper/ColorCombination.java
// public enum ColorCombination {
// VIBRANT_TO_MUTED(0),
// MUTED_TO_VIBRANT(1);
// final int colorCombo;
// ColorCombination(int colorCombo){
// this.colorCombo = colorCombo;
// }
// }
| import android.widget.ImageView;
import proj.me.bitframe.helper.ColorCombination; | package proj.me.bitframe;
/**
* Created by root on 18/4/16.
*/
public class FrameModel {
int commentTransparencyPercent;
int sortDifferenceThreshold;
float minFrameWidth;
float minFrameHeight;
float maxContainerWidth;
float maxContainerHeight;
int maxFrameCount;
int maxExtraCount;
float minAddRatio;
boolean isAddInLayout;
boolean hasLoader;
boolean hasLoadingDrawable;
boolean hasScroll;
boolean shouldShowComment;
boolean hasFixedDimensions;
boolean shouldSortImages; | // Path: bitframe/src/main/java/proj/me/bitframe/helper/ColorCombination.java
// public enum ColorCombination {
// VIBRANT_TO_MUTED(0),
// MUTED_TO_VIBRANT(1);
// final int colorCombo;
// ColorCombination(int colorCombo){
// this.colorCombo = colorCombo;
// }
// }
// Path: bitframe/src/main/java/proj/me/bitframe/FrameModel.java
import android.widget.ImageView;
import proj.me.bitframe.helper.ColorCombination;
package proj.me.bitframe;
/**
* Created by root on 18/4/16.
*/
public class FrameModel {
int commentTransparencyPercent;
int sortDifferenceThreshold;
float minFrameWidth;
float minFrameHeight;
float maxContainerWidth;
float maxContainerHeight;
int maxFrameCount;
int maxExtraCount;
float minAddRatio;
boolean isAddInLayout;
boolean hasLoader;
boolean hasLoadingDrawable;
boolean hasScroll;
boolean shouldShowComment;
boolean hasFixedDimensions;
boolean shouldSortImages; | ColorCombination colorCombination; |
cryptomator/cryptolib | src/test/java/org/cryptomator/cryptolib/common/MasterkeyTest.java | // Path: src/main/java/org/cryptomator/cryptolib/api/Masterkey.java
// public class Masterkey extends DestroyableSecretKey {
//
// private static final String KEY_ALGORITHM = "MASTERKEY";
// public static final String ENC_ALG = "AES";
// public static final String MAC_ALG = "HmacSHA256";
// public static final int SUBKEY_LEN_BYTES = 32;
//
// public Masterkey(byte[] key) {
// super(checkKeyLength(key), KEY_ALGORITHM);
// }
//
// private static byte[] checkKeyLength(byte[] key) {
// Preconditions.checkArgument(key.length == SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES, "Invalid raw key length %s", key.length);
// return key;
// }
//
// public static Masterkey generate(SecureRandom csprng) {
// byte[] key = new byte[SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES];
// try {
// csprng.nextBytes(key);
// return new Masterkey(key);
// } finally {
// Arrays.fill(key, (byte) 0x00);
// }
// }
//
// public static Masterkey from(DestroyableSecretKey encKey, DestroyableSecretKey macKey) {
// Preconditions.checkArgument(encKey.getEncoded().length == SUBKEY_LEN_BYTES, "Invalid key length of encKey");
// Preconditions.checkArgument(macKey.getEncoded().length == SUBKEY_LEN_BYTES, "Invalid key length of macKey");
// byte[] key = new byte[SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES];
// try {
// System.arraycopy(encKey.getEncoded(), 0, key, 0, SUBKEY_LEN_BYTES);
// System.arraycopy(macKey.getEncoded(), 0, key, SUBKEY_LEN_BYTES, SUBKEY_LEN_BYTES);
// return new Masterkey(key);
// } finally {
// Arrays.fill(key, (byte) 0x00);
// }
// }
//
// @Override
// public Masterkey copy() {
// return new Masterkey(getEncoded());
// }
//
// /**
// * Get the encryption subkey.
// *
// * @return A new copy of the subkey used for encryption
// */
// public DestroyableSecretKey getEncKey() {
// return new DestroyableSecretKey(getEncoded(), 0, SUBKEY_LEN_BYTES, ENC_ALG);
// }
//
// /**
// * Get the MAC subkey.
// *
// * @return A new copy of the subkey used for message authentication
// */
// public DestroyableSecretKey getMacKey() {
// return new DestroyableSecretKey(getEncoded(), SUBKEY_LEN_BYTES, SUBKEY_LEN_BYTES, MAC_ALG);
// }
//
// }
| import org.cryptomator.cryptolib.api.Masterkey;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import javax.crypto.SecretKey;
import java.security.SecureRandom;
import java.util.Arrays; | package org.cryptomator.cryptolib.common;
public class MasterkeyTest {
private byte[] raw; | // Path: src/main/java/org/cryptomator/cryptolib/api/Masterkey.java
// public class Masterkey extends DestroyableSecretKey {
//
// private static final String KEY_ALGORITHM = "MASTERKEY";
// public static final String ENC_ALG = "AES";
// public static final String MAC_ALG = "HmacSHA256";
// public static final int SUBKEY_LEN_BYTES = 32;
//
// public Masterkey(byte[] key) {
// super(checkKeyLength(key), KEY_ALGORITHM);
// }
//
// private static byte[] checkKeyLength(byte[] key) {
// Preconditions.checkArgument(key.length == SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES, "Invalid raw key length %s", key.length);
// return key;
// }
//
// public static Masterkey generate(SecureRandom csprng) {
// byte[] key = new byte[SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES];
// try {
// csprng.nextBytes(key);
// return new Masterkey(key);
// } finally {
// Arrays.fill(key, (byte) 0x00);
// }
// }
//
// public static Masterkey from(DestroyableSecretKey encKey, DestroyableSecretKey macKey) {
// Preconditions.checkArgument(encKey.getEncoded().length == SUBKEY_LEN_BYTES, "Invalid key length of encKey");
// Preconditions.checkArgument(macKey.getEncoded().length == SUBKEY_LEN_BYTES, "Invalid key length of macKey");
// byte[] key = new byte[SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES];
// try {
// System.arraycopy(encKey.getEncoded(), 0, key, 0, SUBKEY_LEN_BYTES);
// System.arraycopy(macKey.getEncoded(), 0, key, SUBKEY_LEN_BYTES, SUBKEY_LEN_BYTES);
// return new Masterkey(key);
// } finally {
// Arrays.fill(key, (byte) 0x00);
// }
// }
//
// @Override
// public Masterkey copy() {
// return new Masterkey(getEncoded());
// }
//
// /**
// * Get the encryption subkey.
// *
// * @return A new copy of the subkey used for encryption
// */
// public DestroyableSecretKey getEncKey() {
// return new DestroyableSecretKey(getEncoded(), 0, SUBKEY_LEN_BYTES, ENC_ALG);
// }
//
// /**
// * Get the MAC subkey.
// *
// * @return A new copy of the subkey used for message authentication
// */
// public DestroyableSecretKey getMacKey() {
// return new DestroyableSecretKey(getEncoded(), SUBKEY_LEN_BYTES, SUBKEY_LEN_BYTES, MAC_ALG);
// }
//
// }
// Path: src/test/java/org/cryptomator/cryptolib/common/MasterkeyTest.java
import org.cryptomator.cryptolib.api.Masterkey;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import javax.crypto.SecretKey;
import java.security.SecureRandom;
import java.util.Arrays;
package org.cryptomator.cryptolib.common;
public class MasterkeyTest {
private byte[] raw; | private Masterkey masterkey; |
cryptomator/cryptolib | src/main/java/org/cryptomator/cryptolib/ecies/ECIntegratedEncryptionScheme.java | // Path: src/main/java/org/cryptomator/cryptolib/common/Destroyables.java
// public class Destroyables {
//
// private Destroyables() {
// }
//
// public static void destroySilently(Destroyable destroyable) {
// if (destroyable == null) {
// return;
// }
// try {
// destroyable.destroy();
// } catch (DestroyFailedException e) {
// // no-op
// }
// }
//
// }
| import org.cryptomator.cryptolib.common.Destroyables;
import javax.crypto.AEADBadTagException;
import javax.crypto.KeyAgreement;
import java.security.InvalidKeyException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.interfaces.ECPrivateKey;
import java.security.interfaces.ECPublicKey;
import java.util.Arrays; | package org.cryptomator.cryptolib.ecies;
public class ECIntegratedEncryptionScheme {
/**
* The ECIES used in Cryptomator Hub:
* <ul>
* <li>To be used with {@link org.cryptomator.cryptolib.common.P384KeyPair P-384 EC keys}</li>
* <li>Use ANSI X9.63 KDF with SHA-256 to derive a 352 bit shared secret</li>
* <li>Cut shared secret into 256 bit key + 96 bit nonce used for AES-GCM to encrypt/decrypt</li>
* </ul>
*/
public static final ECIntegratedEncryptionScheme HUB = new ECIntegratedEncryptionScheme(AuthenticatedEncryption.GCM_WITH_SECRET_NONCE, KeyDerivationFunction.ANSI_X963_SHA256_KDF);
private final AuthenticatedEncryption ae;
private final KeyDerivationFunction kdf;
public ECIntegratedEncryptionScheme(AuthenticatedEncryption ae, KeyDerivationFunction kdf) {
this.ae = ae;
this.kdf = kdf;
}
public EncryptedMessage encrypt(KeyPairGenerator ephKeyGen, ECPublicKey receiverPublicKey, byte[] plaintext) {
KeyPair ephKeyPair = ephKeyGen.generateKeyPair();
try {
if (ephKeyPair.getPrivate() instanceof ECPrivateKey) {
assert ephKeyPair.getPublic() instanceof ECPublicKey;
byte[] ciphertext = encrypt((ECPrivateKey) ephKeyPair.getPrivate(), receiverPublicKey, plaintext);
return new EncryptedMessage((ECPublicKey) ephKeyPair.getPublic(), ciphertext);
} else {
throw new IllegalArgumentException("key generator didn't create EC key pair");
}
} finally { | // Path: src/main/java/org/cryptomator/cryptolib/common/Destroyables.java
// public class Destroyables {
//
// private Destroyables() {
// }
//
// public static void destroySilently(Destroyable destroyable) {
// if (destroyable == null) {
// return;
// }
// try {
// destroyable.destroy();
// } catch (DestroyFailedException e) {
// // no-op
// }
// }
//
// }
// Path: src/main/java/org/cryptomator/cryptolib/ecies/ECIntegratedEncryptionScheme.java
import org.cryptomator.cryptolib.common.Destroyables;
import javax.crypto.AEADBadTagException;
import javax.crypto.KeyAgreement;
import java.security.InvalidKeyException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.interfaces.ECPrivateKey;
import java.security.interfaces.ECPublicKey;
import java.util.Arrays;
package org.cryptomator.cryptolib.ecies;
public class ECIntegratedEncryptionScheme {
/**
* The ECIES used in Cryptomator Hub:
* <ul>
* <li>To be used with {@link org.cryptomator.cryptolib.common.P384KeyPair P-384 EC keys}</li>
* <li>Use ANSI X9.63 KDF with SHA-256 to derive a 352 bit shared secret</li>
* <li>Cut shared secret into 256 bit key + 96 bit nonce used for AES-GCM to encrypt/decrypt</li>
* </ul>
*/
public static final ECIntegratedEncryptionScheme HUB = new ECIntegratedEncryptionScheme(AuthenticatedEncryption.GCM_WITH_SECRET_NONCE, KeyDerivationFunction.ANSI_X963_SHA256_KDF);
private final AuthenticatedEncryption ae;
private final KeyDerivationFunction kdf;
public ECIntegratedEncryptionScheme(AuthenticatedEncryption ae, KeyDerivationFunction kdf) {
this.ae = ae;
this.kdf = kdf;
}
public EncryptedMessage encrypt(KeyPairGenerator ephKeyGen, ECPublicKey receiverPublicKey, byte[] plaintext) {
KeyPair ephKeyPair = ephKeyGen.generateKeyPair();
try {
if (ephKeyPair.getPrivate() instanceof ECPrivateKey) {
assert ephKeyPair.getPublic() instanceof ECPublicKey;
byte[] ciphertext = encrypt((ECPrivateKey) ephKeyPair.getPrivate(), receiverPublicKey, plaintext);
return new EncryptedMessage((ECPublicKey) ephKeyPair.getPublic(), ciphertext);
} else {
throw new IllegalArgumentException("key generator didn't create EC key pair");
}
} finally { | Destroyables.destroySilently(ephKeyPair.getPrivate()); |
cryptomator/cryptolib | src/main/java/org/cryptomator/cryptolib/ecies/KeyDerivationFunction.java | // Path: src/main/java/org/cryptomator/cryptolib/common/MessageDigestSupplier.java
// public final class MessageDigestSupplier {
//
// public static final MessageDigestSupplier SHA1 = new MessageDigestSupplier("SHA-1");
// public static final MessageDigestSupplier SHA256 = new MessageDigestSupplier("SHA-256");
//
// private final String digestAlgorithm;
// private final ObjectPool<MessageDigest> mdPool;
//
// public MessageDigestSupplier(String digestAlgorithm) {
// this.digestAlgorithm = digestAlgorithm;
// this.mdPool = new ObjectPool<>(this::createMessageDigest);
// try (ObjectPool.Lease<MessageDigest> lease = mdPool.get()) {
// lease.get(); // eagerly initialize to provoke exceptions
// }
// }
//
// private MessageDigest createMessageDigest() {
// try {
// return MessageDigest.getInstance(digestAlgorithm);
// } catch (NoSuchAlgorithmException e) {
// throw new IllegalArgumentException("Invalid digest algorithm.", e);
// }
// }
//
// /**
// * Leases a reusable MessageDigest.
// *
// * @return A ReusableMessageDigest instance holding a refurbished MessageDigest
// */
// public ObjectPool.Lease<MessageDigest> instance() {
// ObjectPool.Lease<MessageDigest> lease = mdPool.get();
// lease.get().reset();
// return lease;
// }
//
// /**
// * Creates a new MessageDigest.
// *
// * @return New MessageDigest instance
// * @deprecated Use {@link #instance()}
// */
// @Deprecated
// public MessageDigest get() {
// final MessageDigest result = createMessageDigest();
// result.reset();
// return result;
// }
//
// }
//
// Path: src/main/java/org/cryptomator/cryptolib/common/ObjectPool.java
// public class ObjectPool<T> {
//
// private final Queue<WeakReference<T>> returnedInstances;
// private final Supplier<T> factory;
//
// public ObjectPool(Supplier<T> factory) {
// this.returnedInstances = new ConcurrentLinkedQueue<>();
// this.factory = factory;
// }
//
// public Lease<T> get() {
// WeakReference<T> ref;
// while ((ref = returnedInstances.poll()) != null) {
// T cached = ref.get();
// if (cached != null) {
// return new Lease<>(this, cached);
// }
// }
// return new Lease<>(this, factory.get());
// }
//
// /**
// * A holder for resource leased from an {@link ObjectPool}.
// * This is basically an {@link AutoCloseable autocloseable} {@link Supplier} that is intended to be used
// * via try-with-resource blocks.
// *
// * @param <T> Type of the leased instance
// */
// public static class Lease<T> implements AutoCloseable, Supplier<T> {
//
// private final ObjectPool<T> pool;
// private T obj;
//
// private Lease(ObjectPool<T> pool, T obj) {
// this.pool = pool;
// this.obj = obj;
// }
//
// public T get() {
// return obj;
// }
//
// @Override
// public void close() {
// pool.returnedInstances.add(new WeakReference<>(obj));
// obj = null;
// }
// }
//
// }
| import org.cryptomator.cryptolib.common.MessageDigestSupplier;
import org.cryptomator.cryptolib.common.ObjectPool;
import java.math.BigInteger;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.security.DigestException;
import java.security.MessageDigest;
import java.util.Arrays; | package org.cryptomator.cryptolib.ecies;
@FunctionalInterface
public interface KeyDerivationFunction {
KeyDerivationFunction ANSI_X963_SHA256_KDF = (sharedSecret, keyDataLen) -> ansiX963sha256Kdf(sharedSecret, new byte[0], keyDataLen);
/**
* Derives a key of desired length
*
* @param sharedSecret A shared secret
* @param keyDataLen Desired key length (in bytes)
* @return key data
*/
byte[] deriveKey(byte[] sharedSecret, int keyDataLen);
/**
* Performs <a href="https://www.secg.org/sec1-v2.pdf">ANSI-X9.63-KDF</a> with SHA-256
*
* @param sharedSecret A shared secret
* @param sharedInfo Additional authenticated data
* @param keyDataLen Desired key length (in bytes)
* @return key data
*/
static byte[] ansiX963sha256Kdf(byte[] sharedSecret, byte[] sharedInfo, int keyDataLen) {
// max input length is 2^64 - 1, see https://doi.org/10.6028/NIST.SP.800-56Cr2, Table 1
int hashLen = 32; // fixed digest length for SHA-256 in bytes
// These two checks must be performed according to spec. However with 32 bit integers, we can't exceed any limits anyway:
assert BigInteger.valueOf(4L + sharedSecret.length + sharedInfo.length).compareTo(BigInteger.ONE.shiftLeft(64).subtract(BigInteger.ONE)) < 0 : "input larger than hashmaxlen";
assert keyDataLen < (1L << 32 - 1) * hashLen : "keyDataLen larger than hashLen × (2^32 − 1)";
ByteBuffer counter = ByteBuffer.allocate(Integer.BYTES);
assert ByteOrder.BIG_ENDIAN.equals(counter.order());
int n = (keyDataLen + hashLen - 1) / hashLen;
byte[] buffer = new byte[n * hashLen]; | // Path: src/main/java/org/cryptomator/cryptolib/common/MessageDigestSupplier.java
// public final class MessageDigestSupplier {
//
// public static final MessageDigestSupplier SHA1 = new MessageDigestSupplier("SHA-1");
// public static final MessageDigestSupplier SHA256 = new MessageDigestSupplier("SHA-256");
//
// private final String digestAlgorithm;
// private final ObjectPool<MessageDigest> mdPool;
//
// public MessageDigestSupplier(String digestAlgorithm) {
// this.digestAlgorithm = digestAlgorithm;
// this.mdPool = new ObjectPool<>(this::createMessageDigest);
// try (ObjectPool.Lease<MessageDigest> lease = mdPool.get()) {
// lease.get(); // eagerly initialize to provoke exceptions
// }
// }
//
// private MessageDigest createMessageDigest() {
// try {
// return MessageDigest.getInstance(digestAlgorithm);
// } catch (NoSuchAlgorithmException e) {
// throw new IllegalArgumentException("Invalid digest algorithm.", e);
// }
// }
//
// /**
// * Leases a reusable MessageDigest.
// *
// * @return A ReusableMessageDigest instance holding a refurbished MessageDigest
// */
// public ObjectPool.Lease<MessageDigest> instance() {
// ObjectPool.Lease<MessageDigest> lease = mdPool.get();
// lease.get().reset();
// return lease;
// }
//
// /**
// * Creates a new MessageDigest.
// *
// * @return New MessageDigest instance
// * @deprecated Use {@link #instance()}
// */
// @Deprecated
// public MessageDigest get() {
// final MessageDigest result = createMessageDigest();
// result.reset();
// return result;
// }
//
// }
//
// Path: src/main/java/org/cryptomator/cryptolib/common/ObjectPool.java
// public class ObjectPool<T> {
//
// private final Queue<WeakReference<T>> returnedInstances;
// private final Supplier<T> factory;
//
// public ObjectPool(Supplier<T> factory) {
// this.returnedInstances = new ConcurrentLinkedQueue<>();
// this.factory = factory;
// }
//
// public Lease<T> get() {
// WeakReference<T> ref;
// while ((ref = returnedInstances.poll()) != null) {
// T cached = ref.get();
// if (cached != null) {
// return new Lease<>(this, cached);
// }
// }
// return new Lease<>(this, factory.get());
// }
//
// /**
// * A holder for resource leased from an {@link ObjectPool}.
// * This is basically an {@link AutoCloseable autocloseable} {@link Supplier} that is intended to be used
// * via try-with-resource blocks.
// *
// * @param <T> Type of the leased instance
// */
// public static class Lease<T> implements AutoCloseable, Supplier<T> {
//
// private final ObjectPool<T> pool;
// private T obj;
//
// private Lease(ObjectPool<T> pool, T obj) {
// this.pool = pool;
// this.obj = obj;
// }
//
// public T get() {
// return obj;
// }
//
// @Override
// public void close() {
// pool.returnedInstances.add(new WeakReference<>(obj));
// obj = null;
// }
// }
//
// }
// Path: src/main/java/org/cryptomator/cryptolib/ecies/KeyDerivationFunction.java
import org.cryptomator.cryptolib.common.MessageDigestSupplier;
import org.cryptomator.cryptolib.common.ObjectPool;
import java.math.BigInteger;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.security.DigestException;
import java.security.MessageDigest;
import java.util.Arrays;
package org.cryptomator.cryptolib.ecies;
@FunctionalInterface
public interface KeyDerivationFunction {
KeyDerivationFunction ANSI_X963_SHA256_KDF = (sharedSecret, keyDataLen) -> ansiX963sha256Kdf(sharedSecret, new byte[0], keyDataLen);
/**
* Derives a key of desired length
*
* @param sharedSecret A shared secret
* @param keyDataLen Desired key length (in bytes)
* @return key data
*/
byte[] deriveKey(byte[] sharedSecret, int keyDataLen);
/**
* Performs <a href="https://www.secg.org/sec1-v2.pdf">ANSI-X9.63-KDF</a> with SHA-256
*
* @param sharedSecret A shared secret
* @param sharedInfo Additional authenticated data
* @param keyDataLen Desired key length (in bytes)
* @return key data
*/
static byte[] ansiX963sha256Kdf(byte[] sharedSecret, byte[] sharedInfo, int keyDataLen) {
// max input length is 2^64 - 1, see https://doi.org/10.6028/NIST.SP.800-56Cr2, Table 1
int hashLen = 32; // fixed digest length for SHA-256 in bytes
// These two checks must be performed according to spec. However with 32 bit integers, we can't exceed any limits anyway:
assert BigInteger.valueOf(4L + sharedSecret.length + sharedInfo.length).compareTo(BigInteger.ONE.shiftLeft(64).subtract(BigInteger.ONE)) < 0 : "input larger than hashmaxlen";
assert keyDataLen < (1L << 32 - 1) * hashLen : "keyDataLen larger than hashLen × (2^32 − 1)";
ByteBuffer counter = ByteBuffer.allocate(Integer.BYTES);
assert ByteOrder.BIG_ENDIAN.equals(counter.order());
int n = (keyDataLen + hashLen - 1) / hashLen;
byte[] buffer = new byte[n * hashLen]; | try (ObjectPool.Lease<MessageDigest> sha256 = MessageDigestSupplier.SHA256.instance()) { |
cryptomator/cryptolib | src/main/java/org/cryptomator/cryptolib/ecies/KeyDerivationFunction.java | // Path: src/main/java/org/cryptomator/cryptolib/common/MessageDigestSupplier.java
// public final class MessageDigestSupplier {
//
// public static final MessageDigestSupplier SHA1 = new MessageDigestSupplier("SHA-1");
// public static final MessageDigestSupplier SHA256 = new MessageDigestSupplier("SHA-256");
//
// private final String digestAlgorithm;
// private final ObjectPool<MessageDigest> mdPool;
//
// public MessageDigestSupplier(String digestAlgorithm) {
// this.digestAlgorithm = digestAlgorithm;
// this.mdPool = new ObjectPool<>(this::createMessageDigest);
// try (ObjectPool.Lease<MessageDigest> lease = mdPool.get()) {
// lease.get(); // eagerly initialize to provoke exceptions
// }
// }
//
// private MessageDigest createMessageDigest() {
// try {
// return MessageDigest.getInstance(digestAlgorithm);
// } catch (NoSuchAlgorithmException e) {
// throw new IllegalArgumentException("Invalid digest algorithm.", e);
// }
// }
//
// /**
// * Leases a reusable MessageDigest.
// *
// * @return A ReusableMessageDigest instance holding a refurbished MessageDigest
// */
// public ObjectPool.Lease<MessageDigest> instance() {
// ObjectPool.Lease<MessageDigest> lease = mdPool.get();
// lease.get().reset();
// return lease;
// }
//
// /**
// * Creates a new MessageDigest.
// *
// * @return New MessageDigest instance
// * @deprecated Use {@link #instance()}
// */
// @Deprecated
// public MessageDigest get() {
// final MessageDigest result = createMessageDigest();
// result.reset();
// return result;
// }
//
// }
//
// Path: src/main/java/org/cryptomator/cryptolib/common/ObjectPool.java
// public class ObjectPool<T> {
//
// private final Queue<WeakReference<T>> returnedInstances;
// private final Supplier<T> factory;
//
// public ObjectPool(Supplier<T> factory) {
// this.returnedInstances = new ConcurrentLinkedQueue<>();
// this.factory = factory;
// }
//
// public Lease<T> get() {
// WeakReference<T> ref;
// while ((ref = returnedInstances.poll()) != null) {
// T cached = ref.get();
// if (cached != null) {
// return new Lease<>(this, cached);
// }
// }
// return new Lease<>(this, factory.get());
// }
//
// /**
// * A holder for resource leased from an {@link ObjectPool}.
// * This is basically an {@link AutoCloseable autocloseable} {@link Supplier} that is intended to be used
// * via try-with-resource blocks.
// *
// * @param <T> Type of the leased instance
// */
// public static class Lease<T> implements AutoCloseable, Supplier<T> {
//
// private final ObjectPool<T> pool;
// private T obj;
//
// private Lease(ObjectPool<T> pool, T obj) {
// this.pool = pool;
// this.obj = obj;
// }
//
// public T get() {
// return obj;
// }
//
// @Override
// public void close() {
// pool.returnedInstances.add(new WeakReference<>(obj));
// obj = null;
// }
// }
//
// }
| import org.cryptomator.cryptolib.common.MessageDigestSupplier;
import org.cryptomator.cryptolib.common.ObjectPool;
import java.math.BigInteger;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.security.DigestException;
import java.security.MessageDigest;
import java.util.Arrays; | package org.cryptomator.cryptolib.ecies;
@FunctionalInterface
public interface KeyDerivationFunction {
KeyDerivationFunction ANSI_X963_SHA256_KDF = (sharedSecret, keyDataLen) -> ansiX963sha256Kdf(sharedSecret, new byte[0], keyDataLen);
/**
* Derives a key of desired length
*
* @param sharedSecret A shared secret
* @param keyDataLen Desired key length (in bytes)
* @return key data
*/
byte[] deriveKey(byte[] sharedSecret, int keyDataLen);
/**
* Performs <a href="https://www.secg.org/sec1-v2.pdf">ANSI-X9.63-KDF</a> with SHA-256
*
* @param sharedSecret A shared secret
* @param sharedInfo Additional authenticated data
* @param keyDataLen Desired key length (in bytes)
* @return key data
*/
static byte[] ansiX963sha256Kdf(byte[] sharedSecret, byte[] sharedInfo, int keyDataLen) {
// max input length is 2^64 - 1, see https://doi.org/10.6028/NIST.SP.800-56Cr2, Table 1
int hashLen = 32; // fixed digest length for SHA-256 in bytes
// These two checks must be performed according to spec. However with 32 bit integers, we can't exceed any limits anyway:
assert BigInteger.valueOf(4L + sharedSecret.length + sharedInfo.length).compareTo(BigInteger.ONE.shiftLeft(64).subtract(BigInteger.ONE)) < 0 : "input larger than hashmaxlen";
assert keyDataLen < (1L << 32 - 1) * hashLen : "keyDataLen larger than hashLen × (2^32 − 1)";
ByteBuffer counter = ByteBuffer.allocate(Integer.BYTES);
assert ByteOrder.BIG_ENDIAN.equals(counter.order());
int n = (keyDataLen + hashLen - 1) / hashLen;
byte[] buffer = new byte[n * hashLen]; | // Path: src/main/java/org/cryptomator/cryptolib/common/MessageDigestSupplier.java
// public final class MessageDigestSupplier {
//
// public static final MessageDigestSupplier SHA1 = new MessageDigestSupplier("SHA-1");
// public static final MessageDigestSupplier SHA256 = new MessageDigestSupplier("SHA-256");
//
// private final String digestAlgorithm;
// private final ObjectPool<MessageDigest> mdPool;
//
// public MessageDigestSupplier(String digestAlgorithm) {
// this.digestAlgorithm = digestAlgorithm;
// this.mdPool = new ObjectPool<>(this::createMessageDigest);
// try (ObjectPool.Lease<MessageDigest> lease = mdPool.get()) {
// lease.get(); // eagerly initialize to provoke exceptions
// }
// }
//
// private MessageDigest createMessageDigest() {
// try {
// return MessageDigest.getInstance(digestAlgorithm);
// } catch (NoSuchAlgorithmException e) {
// throw new IllegalArgumentException("Invalid digest algorithm.", e);
// }
// }
//
// /**
// * Leases a reusable MessageDigest.
// *
// * @return A ReusableMessageDigest instance holding a refurbished MessageDigest
// */
// public ObjectPool.Lease<MessageDigest> instance() {
// ObjectPool.Lease<MessageDigest> lease = mdPool.get();
// lease.get().reset();
// return lease;
// }
//
// /**
// * Creates a new MessageDigest.
// *
// * @return New MessageDigest instance
// * @deprecated Use {@link #instance()}
// */
// @Deprecated
// public MessageDigest get() {
// final MessageDigest result = createMessageDigest();
// result.reset();
// return result;
// }
//
// }
//
// Path: src/main/java/org/cryptomator/cryptolib/common/ObjectPool.java
// public class ObjectPool<T> {
//
// private final Queue<WeakReference<T>> returnedInstances;
// private final Supplier<T> factory;
//
// public ObjectPool(Supplier<T> factory) {
// this.returnedInstances = new ConcurrentLinkedQueue<>();
// this.factory = factory;
// }
//
// public Lease<T> get() {
// WeakReference<T> ref;
// while ((ref = returnedInstances.poll()) != null) {
// T cached = ref.get();
// if (cached != null) {
// return new Lease<>(this, cached);
// }
// }
// return new Lease<>(this, factory.get());
// }
//
// /**
// * A holder for resource leased from an {@link ObjectPool}.
// * This is basically an {@link AutoCloseable autocloseable} {@link Supplier} that is intended to be used
// * via try-with-resource blocks.
// *
// * @param <T> Type of the leased instance
// */
// public static class Lease<T> implements AutoCloseable, Supplier<T> {
//
// private final ObjectPool<T> pool;
// private T obj;
//
// private Lease(ObjectPool<T> pool, T obj) {
// this.pool = pool;
// this.obj = obj;
// }
//
// public T get() {
// return obj;
// }
//
// @Override
// public void close() {
// pool.returnedInstances.add(new WeakReference<>(obj));
// obj = null;
// }
// }
//
// }
// Path: src/main/java/org/cryptomator/cryptolib/ecies/KeyDerivationFunction.java
import org.cryptomator.cryptolib.common.MessageDigestSupplier;
import org.cryptomator.cryptolib.common.ObjectPool;
import java.math.BigInteger;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.security.DigestException;
import java.security.MessageDigest;
import java.util.Arrays;
package org.cryptomator.cryptolib.ecies;
@FunctionalInterface
public interface KeyDerivationFunction {
KeyDerivationFunction ANSI_X963_SHA256_KDF = (sharedSecret, keyDataLen) -> ansiX963sha256Kdf(sharedSecret, new byte[0], keyDataLen);
/**
* Derives a key of desired length
*
* @param sharedSecret A shared secret
* @param keyDataLen Desired key length (in bytes)
* @return key data
*/
byte[] deriveKey(byte[] sharedSecret, int keyDataLen);
/**
* Performs <a href="https://www.secg.org/sec1-v2.pdf">ANSI-X9.63-KDF</a> with SHA-256
*
* @param sharedSecret A shared secret
* @param sharedInfo Additional authenticated data
* @param keyDataLen Desired key length (in bytes)
* @return key data
*/
static byte[] ansiX963sha256Kdf(byte[] sharedSecret, byte[] sharedInfo, int keyDataLen) {
// max input length is 2^64 - 1, see https://doi.org/10.6028/NIST.SP.800-56Cr2, Table 1
int hashLen = 32; // fixed digest length for SHA-256 in bytes
// These two checks must be performed according to spec. However with 32 bit integers, we can't exceed any limits anyway:
assert BigInteger.valueOf(4L + sharedSecret.length + sharedInfo.length).compareTo(BigInteger.ONE.shiftLeft(64).subtract(BigInteger.ONE)) < 0 : "input larger than hashmaxlen";
assert keyDataLen < (1L << 32 - 1) * hashLen : "keyDataLen larger than hashLen × (2^32 − 1)";
ByteBuffer counter = ByteBuffer.allocate(Integer.BYTES);
assert ByteOrder.BIG_ENDIAN.equals(counter.order());
int n = (keyDataLen + hashLen - 1) / hashLen;
byte[] buffer = new byte[n * hashLen]; | try (ObjectPool.Lease<MessageDigest> sha256 = MessageDigestSupplier.SHA256.instance()) { |
cryptomator/cryptolib | src/test/java/org/cryptomator/cryptolib/common/MasterkeyHubAccessTest.java | // Path: src/main/java/org/cryptomator/cryptolib/api/Masterkey.java
// public class Masterkey extends DestroyableSecretKey {
//
// private static final String KEY_ALGORITHM = "MASTERKEY";
// public static final String ENC_ALG = "AES";
// public static final String MAC_ALG = "HmacSHA256";
// public static final int SUBKEY_LEN_BYTES = 32;
//
// public Masterkey(byte[] key) {
// super(checkKeyLength(key), KEY_ALGORITHM);
// }
//
// private static byte[] checkKeyLength(byte[] key) {
// Preconditions.checkArgument(key.length == SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES, "Invalid raw key length %s", key.length);
// return key;
// }
//
// public static Masterkey generate(SecureRandom csprng) {
// byte[] key = new byte[SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES];
// try {
// csprng.nextBytes(key);
// return new Masterkey(key);
// } finally {
// Arrays.fill(key, (byte) 0x00);
// }
// }
//
// public static Masterkey from(DestroyableSecretKey encKey, DestroyableSecretKey macKey) {
// Preconditions.checkArgument(encKey.getEncoded().length == SUBKEY_LEN_BYTES, "Invalid key length of encKey");
// Preconditions.checkArgument(macKey.getEncoded().length == SUBKEY_LEN_BYTES, "Invalid key length of macKey");
// byte[] key = new byte[SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES];
// try {
// System.arraycopy(encKey.getEncoded(), 0, key, 0, SUBKEY_LEN_BYTES);
// System.arraycopy(macKey.getEncoded(), 0, key, SUBKEY_LEN_BYTES, SUBKEY_LEN_BYTES);
// return new Masterkey(key);
// } finally {
// Arrays.fill(key, (byte) 0x00);
// }
// }
//
// @Override
// public Masterkey copy() {
// return new Masterkey(getEncoded());
// }
//
// /**
// * Get the encryption subkey.
// *
// * @return A new copy of the subkey used for encryption
// */
// public DestroyableSecretKey getEncKey() {
// return new DestroyableSecretKey(getEncoded(), 0, SUBKEY_LEN_BYTES, ENC_ALG);
// }
//
// /**
// * Get the MAC subkey.
// *
// * @return A new copy of the subkey used for message authentication
// */
// public DestroyableSecretKey getMacKey() {
// return new DestroyableSecretKey(getEncoded(), SUBKEY_LEN_BYTES, SUBKEY_LEN_BYTES, MAC_ALG);
// }
//
// }
//
// Path: src/main/java/org/cryptomator/cryptolib/api/MasterkeyLoadingFailedException.java
// public class MasterkeyLoadingFailedException extends CryptoException {
//
// public MasterkeyLoadingFailedException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public MasterkeyLoadingFailedException(String message) {
// super(message);
// }
//
// }
| import com.google.common.io.BaseEncoding;
import org.cryptomator.cryptolib.api.Masterkey;
import org.cryptomator.cryptolib.api.MasterkeyLoadingFailedException;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import java.security.KeyFactory;
import java.security.NoSuchAlgorithmException;
import java.security.interfaces.ECPrivateKey;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.PKCS8EncodedKeySpec;
import java.util.Arrays; | package org.cryptomator.cryptolib.common;
public class MasterkeyHubAccessTest {
private ECPrivateKey devicePrivateKey;
@BeforeEach
public void setup() throws NoSuchAlgorithmException, InvalidKeySpecException {
byte[] keyBytes = BaseEncoding.base64Url().decode("ME4CAQAwEAYHKoZIzj0CAQYFK4EEACIENzA1AgEBBDDzj9mBnoqoYTO0wQDvM2iyI2wrNe468US1mHMjdJcKWGGvky4pMexIvmvmDsZLdsY");
this.devicePrivateKey = (ECPrivateKey) KeyFactory.getInstance("EC").generatePrivate(new PKCS8EncodedKeySpec(keyBytes));
}
@Test
@DisplayName("decryptMasterkey(...)")
public void testDecrypt() {
String ephPk = "MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAEkcv3x-hkCnb8Kr8TNfaLpD4q64ZqPn4p1yuM8r2r16h6f6mG01kFBp2EoY575bCcmT54PxiDFkf3KKqHXFjZwBhdm6zMp22l37ZlmKyHG96vkB7Rh6qFyzEhSQ_nvl2G";
String ciphertext = "KQ48XS6ziW3tS7SMLR5sc2o_Y80OR4SS_htHpk8SHn4KrqI07EtDFFbNJ9AcNOazSu3TXrml--t_bEXprfnPqa3MlBvmPUVBcwUFJPDTR9Y";
| // Path: src/main/java/org/cryptomator/cryptolib/api/Masterkey.java
// public class Masterkey extends DestroyableSecretKey {
//
// private static final String KEY_ALGORITHM = "MASTERKEY";
// public static final String ENC_ALG = "AES";
// public static final String MAC_ALG = "HmacSHA256";
// public static final int SUBKEY_LEN_BYTES = 32;
//
// public Masterkey(byte[] key) {
// super(checkKeyLength(key), KEY_ALGORITHM);
// }
//
// private static byte[] checkKeyLength(byte[] key) {
// Preconditions.checkArgument(key.length == SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES, "Invalid raw key length %s", key.length);
// return key;
// }
//
// public static Masterkey generate(SecureRandom csprng) {
// byte[] key = new byte[SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES];
// try {
// csprng.nextBytes(key);
// return new Masterkey(key);
// } finally {
// Arrays.fill(key, (byte) 0x00);
// }
// }
//
// public static Masterkey from(DestroyableSecretKey encKey, DestroyableSecretKey macKey) {
// Preconditions.checkArgument(encKey.getEncoded().length == SUBKEY_LEN_BYTES, "Invalid key length of encKey");
// Preconditions.checkArgument(macKey.getEncoded().length == SUBKEY_LEN_BYTES, "Invalid key length of macKey");
// byte[] key = new byte[SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES];
// try {
// System.arraycopy(encKey.getEncoded(), 0, key, 0, SUBKEY_LEN_BYTES);
// System.arraycopy(macKey.getEncoded(), 0, key, SUBKEY_LEN_BYTES, SUBKEY_LEN_BYTES);
// return new Masterkey(key);
// } finally {
// Arrays.fill(key, (byte) 0x00);
// }
// }
//
// @Override
// public Masterkey copy() {
// return new Masterkey(getEncoded());
// }
//
// /**
// * Get the encryption subkey.
// *
// * @return A new copy of the subkey used for encryption
// */
// public DestroyableSecretKey getEncKey() {
// return new DestroyableSecretKey(getEncoded(), 0, SUBKEY_LEN_BYTES, ENC_ALG);
// }
//
// /**
// * Get the MAC subkey.
// *
// * @return A new copy of the subkey used for message authentication
// */
// public DestroyableSecretKey getMacKey() {
// return new DestroyableSecretKey(getEncoded(), SUBKEY_LEN_BYTES, SUBKEY_LEN_BYTES, MAC_ALG);
// }
//
// }
//
// Path: src/main/java/org/cryptomator/cryptolib/api/MasterkeyLoadingFailedException.java
// public class MasterkeyLoadingFailedException extends CryptoException {
//
// public MasterkeyLoadingFailedException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public MasterkeyLoadingFailedException(String message) {
// super(message);
// }
//
// }
// Path: src/test/java/org/cryptomator/cryptolib/common/MasterkeyHubAccessTest.java
import com.google.common.io.BaseEncoding;
import org.cryptomator.cryptolib.api.Masterkey;
import org.cryptomator.cryptolib.api.MasterkeyLoadingFailedException;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import java.security.KeyFactory;
import java.security.NoSuchAlgorithmException;
import java.security.interfaces.ECPrivateKey;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.PKCS8EncodedKeySpec;
import java.util.Arrays;
package org.cryptomator.cryptolib.common;
public class MasterkeyHubAccessTest {
private ECPrivateKey devicePrivateKey;
@BeforeEach
public void setup() throws NoSuchAlgorithmException, InvalidKeySpecException {
byte[] keyBytes = BaseEncoding.base64Url().decode("ME4CAQAwEAYHKoZIzj0CAQYFK4EEACIENzA1AgEBBDDzj9mBnoqoYTO0wQDvM2iyI2wrNe468US1mHMjdJcKWGGvky4pMexIvmvmDsZLdsY");
this.devicePrivateKey = (ECPrivateKey) KeyFactory.getInstance("EC").generatePrivate(new PKCS8EncodedKeySpec(keyBytes));
}
@Test
@DisplayName("decryptMasterkey(...)")
public void testDecrypt() {
String ephPk = "MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAEkcv3x-hkCnb8Kr8TNfaLpD4q64ZqPn4p1yuM8r2r16h6f6mG01kFBp2EoY575bCcmT54PxiDFkf3KKqHXFjZwBhdm6zMp22l37ZlmKyHG96vkB7Rh6qFyzEhSQ_nvl2G";
String ciphertext = "KQ48XS6ziW3tS7SMLR5sc2o_Y80OR4SS_htHpk8SHn4KrqI07EtDFFbNJ9AcNOazSu3TXrml--t_bEXprfnPqa3MlBvmPUVBcwUFJPDTR9Y";
| Masterkey masterkey = MasterkeyHubAccess.decryptMasterkey(devicePrivateKey, ciphertext, ephPk); |
cryptomator/cryptolib | src/main/java/org/cryptomator/cryptolib/common/EncryptingReadableByteChannel.java | // Path: src/main/java/org/cryptomator/cryptolib/api/Cryptor.java
// public interface Cryptor extends Destroyable, AutoCloseable {
//
// FileContentCryptor fileContentCryptor();
//
// FileHeaderCryptor fileHeaderCryptor();
//
// FileNameCryptor fileNameCryptor();
//
// @Override
// void destroy();
//
// /**
// * Calls {@link #destroy()}.
// */
// @Override
// default void close() {
// destroy();
// }
//
// }
//
// Path: src/main/java/org/cryptomator/cryptolib/api/FileHeader.java
// public interface FileHeader {
//
// /**
// * Returns the value of a currently unused 64 bit field in the file header.
// * <p>
// * Formerly used for storing the plaintext file size.
// *
// * @return 64 bit integer for future use.
// * @deprecated Don't rely on this method. It may be redefined any time.
// */
// @Deprecated
// long getReserved();
//
// /**
// * Sets the 64 bit field in the file header.
// * <p>
// * Formerly used for storing the plaintext file size.
// *
// * @param reserved 64 bit integer for future use
// * @deprecated Don't rely on this method. It may be redefined any time.
// */
// @Deprecated
// void setReserved(long reserved);
//
// }
| import org.cryptomator.cryptolib.api.Cryptor;
import org.cryptomator.cryptolib.api.FileHeader;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.ReadableByteChannel; | package org.cryptomator.cryptolib.common;
public class EncryptingReadableByteChannel implements ReadableByteChannel {
private final ReadableByteChannel delegate; | // Path: src/main/java/org/cryptomator/cryptolib/api/Cryptor.java
// public interface Cryptor extends Destroyable, AutoCloseable {
//
// FileContentCryptor fileContentCryptor();
//
// FileHeaderCryptor fileHeaderCryptor();
//
// FileNameCryptor fileNameCryptor();
//
// @Override
// void destroy();
//
// /**
// * Calls {@link #destroy()}.
// */
// @Override
// default void close() {
// destroy();
// }
//
// }
//
// Path: src/main/java/org/cryptomator/cryptolib/api/FileHeader.java
// public interface FileHeader {
//
// /**
// * Returns the value of a currently unused 64 bit field in the file header.
// * <p>
// * Formerly used for storing the plaintext file size.
// *
// * @return 64 bit integer for future use.
// * @deprecated Don't rely on this method. It may be redefined any time.
// */
// @Deprecated
// long getReserved();
//
// /**
// * Sets the 64 bit field in the file header.
// * <p>
// * Formerly used for storing the plaintext file size.
// *
// * @param reserved 64 bit integer for future use
// * @deprecated Don't rely on this method. It may be redefined any time.
// */
// @Deprecated
// void setReserved(long reserved);
//
// }
// Path: src/main/java/org/cryptomator/cryptolib/common/EncryptingReadableByteChannel.java
import org.cryptomator.cryptolib.api.Cryptor;
import org.cryptomator.cryptolib.api.FileHeader;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.ReadableByteChannel;
package org.cryptomator.cryptolib.common;
public class EncryptingReadableByteChannel implements ReadableByteChannel {
private final ReadableByteChannel delegate; | private final Cryptor cryptor; |
cryptomator/cryptolib | src/main/java/org/cryptomator/cryptolib/common/EncryptingReadableByteChannel.java | // Path: src/main/java/org/cryptomator/cryptolib/api/Cryptor.java
// public interface Cryptor extends Destroyable, AutoCloseable {
//
// FileContentCryptor fileContentCryptor();
//
// FileHeaderCryptor fileHeaderCryptor();
//
// FileNameCryptor fileNameCryptor();
//
// @Override
// void destroy();
//
// /**
// * Calls {@link #destroy()}.
// */
// @Override
// default void close() {
// destroy();
// }
//
// }
//
// Path: src/main/java/org/cryptomator/cryptolib/api/FileHeader.java
// public interface FileHeader {
//
// /**
// * Returns the value of a currently unused 64 bit field in the file header.
// * <p>
// * Formerly used for storing the plaintext file size.
// *
// * @return 64 bit integer for future use.
// * @deprecated Don't rely on this method. It may be redefined any time.
// */
// @Deprecated
// long getReserved();
//
// /**
// * Sets the 64 bit field in the file header.
// * <p>
// * Formerly used for storing the plaintext file size.
// *
// * @param reserved 64 bit integer for future use
// * @deprecated Don't rely on this method. It may be redefined any time.
// */
// @Deprecated
// void setReserved(long reserved);
//
// }
| import org.cryptomator.cryptolib.api.Cryptor;
import org.cryptomator.cryptolib.api.FileHeader;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.ReadableByteChannel; | package org.cryptomator.cryptolib.common;
public class EncryptingReadableByteChannel implements ReadableByteChannel {
private final ReadableByteChannel delegate;
private final Cryptor cryptor; | // Path: src/main/java/org/cryptomator/cryptolib/api/Cryptor.java
// public interface Cryptor extends Destroyable, AutoCloseable {
//
// FileContentCryptor fileContentCryptor();
//
// FileHeaderCryptor fileHeaderCryptor();
//
// FileNameCryptor fileNameCryptor();
//
// @Override
// void destroy();
//
// /**
// * Calls {@link #destroy()}.
// */
// @Override
// default void close() {
// destroy();
// }
//
// }
//
// Path: src/main/java/org/cryptomator/cryptolib/api/FileHeader.java
// public interface FileHeader {
//
// /**
// * Returns the value of a currently unused 64 bit field in the file header.
// * <p>
// * Formerly used for storing the plaintext file size.
// *
// * @return 64 bit integer for future use.
// * @deprecated Don't rely on this method. It may be redefined any time.
// */
// @Deprecated
// long getReserved();
//
// /**
// * Sets the 64 bit field in the file header.
// * <p>
// * Formerly used for storing the plaintext file size.
// *
// * @param reserved 64 bit integer for future use
// * @deprecated Don't rely on this method. It may be redefined any time.
// */
// @Deprecated
// void setReserved(long reserved);
//
// }
// Path: src/main/java/org/cryptomator/cryptolib/common/EncryptingReadableByteChannel.java
import org.cryptomator.cryptolib.api.Cryptor;
import org.cryptomator.cryptolib.api.FileHeader;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.ReadableByteChannel;
package org.cryptomator.cryptolib.common;
public class EncryptingReadableByteChannel implements ReadableByteChannel {
private final ReadableByteChannel delegate;
private final Cryptor cryptor; | private final FileHeader header; |
cryptomator/cryptolib | src/test/java/org/cryptomator/cryptolib/common/MasterkeyFileAccessTest.java | // Path: src/main/java/org/cryptomator/cryptolib/api/CryptoException.java
// public abstract class CryptoException extends RuntimeException {
//
// protected CryptoException() {
// super();
// }
//
// protected CryptoException(String message) {
// super(message);
// }
//
// protected CryptoException(String message, Throwable cause) {
// super(message, cause);
// }
//
// }
//
// Path: src/main/java/org/cryptomator/cryptolib/api/InvalidPassphraseException.java
// public class InvalidPassphraseException extends MasterkeyLoadingFailedException {
//
// public InvalidPassphraseException() {
// super(null);
// }
// }
//
// Path: src/main/java/org/cryptomator/cryptolib/api/Masterkey.java
// public class Masterkey extends DestroyableSecretKey {
//
// private static final String KEY_ALGORITHM = "MASTERKEY";
// public static final String ENC_ALG = "AES";
// public static final String MAC_ALG = "HmacSHA256";
// public static final int SUBKEY_LEN_BYTES = 32;
//
// public Masterkey(byte[] key) {
// super(checkKeyLength(key), KEY_ALGORITHM);
// }
//
// private static byte[] checkKeyLength(byte[] key) {
// Preconditions.checkArgument(key.length == SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES, "Invalid raw key length %s", key.length);
// return key;
// }
//
// public static Masterkey generate(SecureRandom csprng) {
// byte[] key = new byte[SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES];
// try {
// csprng.nextBytes(key);
// return new Masterkey(key);
// } finally {
// Arrays.fill(key, (byte) 0x00);
// }
// }
//
// public static Masterkey from(DestroyableSecretKey encKey, DestroyableSecretKey macKey) {
// Preconditions.checkArgument(encKey.getEncoded().length == SUBKEY_LEN_BYTES, "Invalid key length of encKey");
// Preconditions.checkArgument(macKey.getEncoded().length == SUBKEY_LEN_BYTES, "Invalid key length of macKey");
// byte[] key = new byte[SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES];
// try {
// System.arraycopy(encKey.getEncoded(), 0, key, 0, SUBKEY_LEN_BYTES);
// System.arraycopy(macKey.getEncoded(), 0, key, SUBKEY_LEN_BYTES, SUBKEY_LEN_BYTES);
// return new Masterkey(key);
// } finally {
// Arrays.fill(key, (byte) 0x00);
// }
// }
//
// @Override
// public Masterkey copy() {
// return new Masterkey(getEncoded());
// }
//
// /**
// * Get the encryption subkey.
// *
// * @return A new copy of the subkey used for encryption
// */
// public DestroyableSecretKey getEncKey() {
// return new DestroyableSecretKey(getEncoded(), 0, SUBKEY_LEN_BYTES, ENC_ALG);
// }
//
// /**
// * Get the MAC subkey.
// *
// * @return A new copy of the subkey used for message authentication
// */
// public DestroyableSecretKey getMacKey() {
// return new DestroyableSecretKey(getEncoded(), SUBKEY_LEN_BYTES, SUBKEY_LEN_BYTES, MAC_ALG);
// }
//
// }
//
// Path: src/main/java/org/cryptomator/cryptolib/api/MasterkeyLoadingFailedException.java
// public class MasterkeyLoadingFailedException extends CryptoException {
//
// public MasterkeyLoadingFailedException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public MasterkeyLoadingFailedException(String message) {
// super(message);
// }
//
// }
| import com.google.common.io.BaseEncoding;
import org.cryptomator.cryptolib.api.CryptoException;
import org.cryptomator.cryptolib.api.InvalidPassphraseException;
import org.cryptomator.cryptolib.api.Masterkey;
import org.cryptomator.cryptolib.api.MasterkeyLoadingFailedException;
import org.hamcrest.MatcherAssert;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.mockito.Mockito;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Path;
import java.security.SecureRandom;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.hamcrest.core.IsNot.not; | package org.cryptomator.cryptolib.common;
public class MasterkeyFileAccessTest {
private static final SecureRandom RANDOM_MOCK = SecureRandomMock.NULL_RANDOM;
private static final byte[] DEFAULT_PEPPER = new byte[0];
| // Path: src/main/java/org/cryptomator/cryptolib/api/CryptoException.java
// public abstract class CryptoException extends RuntimeException {
//
// protected CryptoException() {
// super();
// }
//
// protected CryptoException(String message) {
// super(message);
// }
//
// protected CryptoException(String message, Throwable cause) {
// super(message, cause);
// }
//
// }
//
// Path: src/main/java/org/cryptomator/cryptolib/api/InvalidPassphraseException.java
// public class InvalidPassphraseException extends MasterkeyLoadingFailedException {
//
// public InvalidPassphraseException() {
// super(null);
// }
// }
//
// Path: src/main/java/org/cryptomator/cryptolib/api/Masterkey.java
// public class Masterkey extends DestroyableSecretKey {
//
// private static final String KEY_ALGORITHM = "MASTERKEY";
// public static final String ENC_ALG = "AES";
// public static final String MAC_ALG = "HmacSHA256";
// public static final int SUBKEY_LEN_BYTES = 32;
//
// public Masterkey(byte[] key) {
// super(checkKeyLength(key), KEY_ALGORITHM);
// }
//
// private static byte[] checkKeyLength(byte[] key) {
// Preconditions.checkArgument(key.length == SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES, "Invalid raw key length %s", key.length);
// return key;
// }
//
// public static Masterkey generate(SecureRandom csprng) {
// byte[] key = new byte[SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES];
// try {
// csprng.nextBytes(key);
// return new Masterkey(key);
// } finally {
// Arrays.fill(key, (byte) 0x00);
// }
// }
//
// public static Masterkey from(DestroyableSecretKey encKey, DestroyableSecretKey macKey) {
// Preconditions.checkArgument(encKey.getEncoded().length == SUBKEY_LEN_BYTES, "Invalid key length of encKey");
// Preconditions.checkArgument(macKey.getEncoded().length == SUBKEY_LEN_BYTES, "Invalid key length of macKey");
// byte[] key = new byte[SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES];
// try {
// System.arraycopy(encKey.getEncoded(), 0, key, 0, SUBKEY_LEN_BYTES);
// System.arraycopy(macKey.getEncoded(), 0, key, SUBKEY_LEN_BYTES, SUBKEY_LEN_BYTES);
// return new Masterkey(key);
// } finally {
// Arrays.fill(key, (byte) 0x00);
// }
// }
//
// @Override
// public Masterkey copy() {
// return new Masterkey(getEncoded());
// }
//
// /**
// * Get the encryption subkey.
// *
// * @return A new copy of the subkey used for encryption
// */
// public DestroyableSecretKey getEncKey() {
// return new DestroyableSecretKey(getEncoded(), 0, SUBKEY_LEN_BYTES, ENC_ALG);
// }
//
// /**
// * Get the MAC subkey.
// *
// * @return A new copy of the subkey used for message authentication
// */
// public DestroyableSecretKey getMacKey() {
// return new DestroyableSecretKey(getEncoded(), SUBKEY_LEN_BYTES, SUBKEY_LEN_BYTES, MAC_ALG);
// }
//
// }
//
// Path: src/main/java/org/cryptomator/cryptolib/api/MasterkeyLoadingFailedException.java
// public class MasterkeyLoadingFailedException extends CryptoException {
//
// public MasterkeyLoadingFailedException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public MasterkeyLoadingFailedException(String message) {
// super(message);
// }
//
// }
// Path: src/test/java/org/cryptomator/cryptolib/common/MasterkeyFileAccessTest.java
import com.google.common.io.BaseEncoding;
import org.cryptomator.cryptolib.api.CryptoException;
import org.cryptomator.cryptolib.api.InvalidPassphraseException;
import org.cryptomator.cryptolib.api.Masterkey;
import org.cryptomator.cryptolib.api.MasterkeyLoadingFailedException;
import org.hamcrest.MatcherAssert;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.mockito.Mockito;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Path;
import java.security.SecureRandom;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.hamcrest.core.IsNot.not;
package org.cryptomator.cryptolib.common;
public class MasterkeyFileAccessTest {
private static final SecureRandom RANDOM_MOCK = SecureRandomMock.NULL_RANDOM;
private static final byte[] DEFAULT_PEPPER = new byte[0];
| private Masterkey key = new Masterkey(new byte[64]); |
cryptomator/cryptolib | src/test/java/org/cryptomator/cryptolib/common/MasterkeyFileAccessTest.java | // Path: src/main/java/org/cryptomator/cryptolib/api/CryptoException.java
// public abstract class CryptoException extends RuntimeException {
//
// protected CryptoException() {
// super();
// }
//
// protected CryptoException(String message) {
// super(message);
// }
//
// protected CryptoException(String message, Throwable cause) {
// super(message, cause);
// }
//
// }
//
// Path: src/main/java/org/cryptomator/cryptolib/api/InvalidPassphraseException.java
// public class InvalidPassphraseException extends MasterkeyLoadingFailedException {
//
// public InvalidPassphraseException() {
// super(null);
// }
// }
//
// Path: src/main/java/org/cryptomator/cryptolib/api/Masterkey.java
// public class Masterkey extends DestroyableSecretKey {
//
// private static final String KEY_ALGORITHM = "MASTERKEY";
// public static final String ENC_ALG = "AES";
// public static final String MAC_ALG = "HmacSHA256";
// public static final int SUBKEY_LEN_BYTES = 32;
//
// public Masterkey(byte[] key) {
// super(checkKeyLength(key), KEY_ALGORITHM);
// }
//
// private static byte[] checkKeyLength(byte[] key) {
// Preconditions.checkArgument(key.length == SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES, "Invalid raw key length %s", key.length);
// return key;
// }
//
// public static Masterkey generate(SecureRandom csprng) {
// byte[] key = new byte[SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES];
// try {
// csprng.nextBytes(key);
// return new Masterkey(key);
// } finally {
// Arrays.fill(key, (byte) 0x00);
// }
// }
//
// public static Masterkey from(DestroyableSecretKey encKey, DestroyableSecretKey macKey) {
// Preconditions.checkArgument(encKey.getEncoded().length == SUBKEY_LEN_BYTES, "Invalid key length of encKey");
// Preconditions.checkArgument(macKey.getEncoded().length == SUBKEY_LEN_BYTES, "Invalid key length of macKey");
// byte[] key = new byte[SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES];
// try {
// System.arraycopy(encKey.getEncoded(), 0, key, 0, SUBKEY_LEN_BYTES);
// System.arraycopy(macKey.getEncoded(), 0, key, SUBKEY_LEN_BYTES, SUBKEY_LEN_BYTES);
// return new Masterkey(key);
// } finally {
// Arrays.fill(key, (byte) 0x00);
// }
// }
//
// @Override
// public Masterkey copy() {
// return new Masterkey(getEncoded());
// }
//
// /**
// * Get the encryption subkey.
// *
// * @return A new copy of the subkey used for encryption
// */
// public DestroyableSecretKey getEncKey() {
// return new DestroyableSecretKey(getEncoded(), 0, SUBKEY_LEN_BYTES, ENC_ALG);
// }
//
// /**
// * Get the MAC subkey.
// *
// * @return A new copy of the subkey used for message authentication
// */
// public DestroyableSecretKey getMacKey() {
// return new DestroyableSecretKey(getEncoded(), SUBKEY_LEN_BYTES, SUBKEY_LEN_BYTES, MAC_ALG);
// }
//
// }
//
// Path: src/main/java/org/cryptomator/cryptolib/api/MasterkeyLoadingFailedException.java
// public class MasterkeyLoadingFailedException extends CryptoException {
//
// public MasterkeyLoadingFailedException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public MasterkeyLoadingFailedException(String message) {
// super(message);
// }
//
// }
| import com.google.common.io.BaseEncoding;
import org.cryptomator.cryptolib.api.CryptoException;
import org.cryptomator.cryptolib.api.InvalidPassphraseException;
import org.cryptomator.cryptolib.api.Masterkey;
import org.cryptomator.cryptolib.api.MasterkeyLoadingFailedException;
import org.hamcrest.MatcherAssert;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.mockito.Mockito;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Path;
import java.security.SecureRandom;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.hamcrest.core.IsNot.not; | }
@Test
@DisplayName("load() non-json file")
public void testLoadMalformed() {
final String content = "not even json";
InputStream in = new ByteArrayInputStream(content.getBytes(UTF_8));
Assertions.assertThrows(IOException.class, () -> {
masterkeyFileAccess.load(in, "asd");
});
}
}
@Nested
@DisplayName("unlock()")
class Unlock {
@Test
@DisplayName("with correct password")
public void testUnlockWithCorrectPassword() throws CryptoException {
Masterkey key = masterkeyFileAccess.unlock(keyFile, "asd");
Assertions.assertNotNull(key);
}
@Test
@DisplayName("with invalid password")
public void testUnlockWithIncorrectPassword() { | // Path: src/main/java/org/cryptomator/cryptolib/api/CryptoException.java
// public abstract class CryptoException extends RuntimeException {
//
// protected CryptoException() {
// super();
// }
//
// protected CryptoException(String message) {
// super(message);
// }
//
// protected CryptoException(String message, Throwable cause) {
// super(message, cause);
// }
//
// }
//
// Path: src/main/java/org/cryptomator/cryptolib/api/InvalidPassphraseException.java
// public class InvalidPassphraseException extends MasterkeyLoadingFailedException {
//
// public InvalidPassphraseException() {
// super(null);
// }
// }
//
// Path: src/main/java/org/cryptomator/cryptolib/api/Masterkey.java
// public class Masterkey extends DestroyableSecretKey {
//
// private static final String KEY_ALGORITHM = "MASTERKEY";
// public static final String ENC_ALG = "AES";
// public static final String MAC_ALG = "HmacSHA256";
// public static final int SUBKEY_LEN_BYTES = 32;
//
// public Masterkey(byte[] key) {
// super(checkKeyLength(key), KEY_ALGORITHM);
// }
//
// private static byte[] checkKeyLength(byte[] key) {
// Preconditions.checkArgument(key.length == SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES, "Invalid raw key length %s", key.length);
// return key;
// }
//
// public static Masterkey generate(SecureRandom csprng) {
// byte[] key = new byte[SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES];
// try {
// csprng.nextBytes(key);
// return new Masterkey(key);
// } finally {
// Arrays.fill(key, (byte) 0x00);
// }
// }
//
// public static Masterkey from(DestroyableSecretKey encKey, DestroyableSecretKey macKey) {
// Preconditions.checkArgument(encKey.getEncoded().length == SUBKEY_LEN_BYTES, "Invalid key length of encKey");
// Preconditions.checkArgument(macKey.getEncoded().length == SUBKEY_LEN_BYTES, "Invalid key length of macKey");
// byte[] key = new byte[SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES];
// try {
// System.arraycopy(encKey.getEncoded(), 0, key, 0, SUBKEY_LEN_BYTES);
// System.arraycopy(macKey.getEncoded(), 0, key, SUBKEY_LEN_BYTES, SUBKEY_LEN_BYTES);
// return new Masterkey(key);
// } finally {
// Arrays.fill(key, (byte) 0x00);
// }
// }
//
// @Override
// public Masterkey copy() {
// return new Masterkey(getEncoded());
// }
//
// /**
// * Get the encryption subkey.
// *
// * @return A new copy of the subkey used for encryption
// */
// public DestroyableSecretKey getEncKey() {
// return new DestroyableSecretKey(getEncoded(), 0, SUBKEY_LEN_BYTES, ENC_ALG);
// }
//
// /**
// * Get the MAC subkey.
// *
// * @return A new copy of the subkey used for message authentication
// */
// public DestroyableSecretKey getMacKey() {
// return new DestroyableSecretKey(getEncoded(), SUBKEY_LEN_BYTES, SUBKEY_LEN_BYTES, MAC_ALG);
// }
//
// }
//
// Path: src/main/java/org/cryptomator/cryptolib/api/MasterkeyLoadingFailedException.java
// public class MasterkeyLoadingFailedException extends CryptoException {
//
// public MasterkeyLoadingFailedException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public MasterkeyLoadingFailedException(String message) {
// super(message);
// }
//
// }
// Path: src/test/java/org/cryptomator/cryptolib/common/MasterkeyFileAccessTest.java
import com.google.common.io.BaseEncoding;
import org.cryptomator.cryptolib.api.CryptoException;
import org.cryptomator.cryptolib.api.InvalidPassphraseException;
import org.cryptomator.cryptolib.api.Masterkey;
import org.cryptomator.cryptolib.api.MasterkeyLoadingFailedException;
import org.hamcrest.MatcherAssert;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.mockito.Mockito;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Path;
import java.security.SecureRandom;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.hamcrest.core.IsNot.not;
}
@Test
@DisplayName("load() non-json file")
public void testLoadMalformed() {
final String content = "not even json";
InputStream in = new ByteArrayInputStream(content.getBytes(UTF_8));
Assertions.assertThrows(IOException.class, () -> {
masterkeyFileAccess.load(in, "asd");
});
}
}
@Nested
@DisplayName("unlock()")
class Unlock {
@Test
@DisplayName("with correct password")
public void testUnlockWithCorrectPassword() throws CryptoException {
Masterkey key = masterkeyFileAccess.unlock(keyFile, "asd");
Assertions.assertNotNull(key);
}
@Test
@DisplayName("with invalid password")
public void testUnlockWithIncorrectPassword() { | Assertions.assertThrows(InvalidPassphraseException.class, () -> { |
cryptomator/cryptolib | src/test/java/org/cryptomator/cryptolib/v2/CryptorProviderImplTest.java | // Path: src/main/java/org/cryptomator/cryptolib/api/Masterkey.java
// public class Masterkey extends DestroyableSecretKey {
//
// private static final String KEY_ALGORITHM = "MASTERKEY";
// public static final String ENC_ALG = "AES";
// public static final String MAC_ALG = "HmacSHA256";
// public static final int SUBKEY_LEN_BYTES = 32;
//
// public Masterkey(byte[] key) {
// super(checkKeyLength(key), KEY_ALGORITHM);
// }
//
// private static byte[] checkKeyLength(byte[] key) {
// Preconditions.checkArgument(key.length == SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES, "Invalid raw key length %s", key.length);
// return key;
// }
//
// public static Masterkey generate(SecureRandom csprng) {
// byte[] key = new byte[SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES];
// try {
// csprng.nextBytes(key);
// return new Masterkey(key);
// } finally {
// Arrays.fill(key, (byte) 0x00);
// }
// }
//
// public static Masterkey from(DestroyableSecretKey encKey, DestroyableSecretKey macKey) {
// Preconditions.checkArgument(encKey.getEncoded().length == SUBKEY_LEN_BYTES, "Invalid key length of encKey");
// Preconditions.checkArgument(macKey.getEncoded().length == SUBKEY_LEN_BYTES, "Invalid key length of macKey");
// byte[] key = new byte[SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES];
// try {
// System.arraycopy(encKey.getEncoded(), 0, key, 0, SUBKEY_LEN_BYTES);
// System.arraycopy(macKey.getEncoded(), 0, key, SUBKEY_LEN_BYTES, SUBKEY_LEN_BYTES);
// return new Masterkey(key);
// } finally {
// Arrays.fill(key, (byte) 0x00);
// }
// }
//
// @Override
// public Masterkey copy() {
// return new Masterkey(getEncoded());
// }
//
// /**
// * Get the encryption subkey.
// *
// * @return A new copy of the subkey used for encryption
// */
// public DestroyableSecretKey getEncKey() {
// return new DestroyableSecretKey(getEncoded(), 0, SUBKEY_LEN_BYTES, ENC_ALG);
// }
//
// /**
// * Get the MAC subkey.
// *
// * @return A new copy of the subkey used for message authentication
// */
// public DestroyableSecretKey getMacKey() {
// return new DestroyableSecretKey(getEncoded(), SUBKEY_LEN_BYTES, SUBKEY_LEN_BYTES, MAC_ALG);
// }
//
// }
//
// Path: src/test/java/org/cryptomator/cryptolib/common/SecureRandomMock.java
// public class SecureRandomMock extends SecureRandom {
//
// private static final ByteFiller NULL_FILLER = bytes -> Arrays.fill(bytes, (byte) 0x00);
// public static final SecureRandomMock NULL_RANDOM = new SecureRandomMock(NULL_FILLER);
// private static final ByteFiller PRNG_FILLER = new ByteFiller() {
//
// private final Random random = new Random();
//
// @Override
// public void fill(byte[] bytes) {
// random.nextBytes(bytes);
// }
//
// };
// public static final SecureRandomMock PRNG_RANDOM = new SecureRandomMock(PRNG_FILLER);
//
// private final ByteFiller byteFiller;
//
// public SecureRandomMock(ByteFiller byteFiller) {
// this.byteFiller = byteFiller;
// }
//
// @Override
// public void nextBytes(byte[] bytes) {
// byteFiller.fill(bytes);
// }
//
// public static SecureRandomMock cycle(byte... bytes) {
// return new SecureRandomMock(new CyclicByteFiller(bytes));
// }
//
// public interface ByteFiller {
// void fill(byte[] bytes);
// }
//
// private static class CyclicByteFiller implements ByteFiller {
//
// private final Iterator<Byte> source;
//
// CyclicByteFiller(byte... bytes) {
// source = Iterators.cycle(Bytes.asList(bytes));
// }
//
// @Override
// public void fill(byte[] bytes) {
// Arrays.fill(bytes, source.next());
// }
//
// }
//
// }
| import org.cryptomator.cryptolib.api.Masterkey;
import org.cryptomator.cryptolib.common.SecureRandomMock;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import java.security.SecureRandom; | /*******************************************************************************
* Copyright (c) 2016 Sebastian Stenzel and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the accompanying LICENSE.txt.
*
* Contributors:
* Sebastian Stenzel - initial API and implementation
*******************************************************************************/
package org.cryptomator.cryptolib.v2;
public class CryptorProviderImplTest {
private static final SecureRandom RANDOM_MOCK = SecureRandomMock.NULL_RANDOM;
@Test
public void testProvide() { | // Path: src/main/java/org/cryptomator/cryptolib/api/Masterkey.java
// public class Masterkey extends DestroyableSecretKey {
//
// private static final String KEY_ALGORITHM = "MASTERKEY";
// public static final String ENC_ALG = "AES";
// public static final String MAC_ALG = "HmacSHA256";
// public static final int SUBKEY_LEN_BYTES = 32;
//
// public Masterkey(byte[] key) {
// super(checkKeyLength(key), KEY_ALGORITHM);
// }
//
// private static byte[] checkKeyLength(byte[] key) {
// Preconditions.checkArgument(key.length == SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES, "Invalid raw key length %s", key.length);
// return key;
// }
//
// public static Masterkey generate(SecureRandom csprng) {
// byte[] key = new byte[SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES];
// try {
// csprng.nextBytes(key);
// return new Masterkey(key);
// } finally {
// Arrays.fill(key, (byte) 0x00);
// }
// }
//
// public static Masterkey from(DestroyableSecretKey encKey, DestroyableSecretKey macKey) {
// Preconditions.checkArgument(encKey.getEncoded().length == SUBKEY_LEN_BYTES, "Invalid key length of encKey");
// Preconditions.checkArgument(macKey.getEncoded().length == SUBKEY_LEN_BYTES, "Invalid key length of macKey");
// byte[] key = new byte[SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES];
// try {
// System.arraycopy(encKey.getEncoded(), 0, key, 0, SUBKEY_LEN_BYTES);
// System.arraycopy(macKey.getEncoded(), 0, key, SUBKEY_LEN_BYTES, SUBKEY_LEN_BYTES);
// return new Masterkey(key);
// } finally {
// Arrays.fill(key, (byte) 0x00);
// }
// }
//
// @Override
// public Masterkey copy() {
// return new Masterkey(getEncoded());
// }
//
// /**
// * Get the encryption subkey.
// *
// * @return A new copy of the subkey used for encryption
// */
// public DestroyableSecretKey getEncKey() {
// return new DestroyableSecretKey(getEncoded(), 0, SUBKEY_LEN_BYTES, ENC_ALG);
// }
//
// /**
// * Get the MAC subkey.
// *
// * @return A new copy of the subkey used for message authentication
// */
// public DestroyableSecretKey getMacKey() {
// return new DestroyableSecretKey(getEncoded(), SUBKEY_LEN_BYTES, SUBKEY_LEN_BYTES, MAC_ALG);
// }
//
// }
//
// Path: src/test/java/org/cryptomator/cryptolib/common/SecureRandomMock.java
// public class SecureRandomMock extends SecureRandom {
//
// private static final ByteFiller NULL_FILLER = bytes -> Arrays.fill(bytes, (byte) 0x00);
// public static final SecureRandomMock NULL_RANDOM = new SecureRandomMock(NULL_FILLER);
// private static final ByteFiller PRNG_FILLER = new ByteFiller() {
//
// private final Random random = new Random();
//
// @Override
// public void fill(byte[] bytes) {
// random.nextBytes(bytes);
// }
//
// };
// public static final SecureRandomMock PRNG_RANDOM = new SecureRandomMock(PRNG_FILLER);
//
// private final ByteFiller byteFiller;
//
// public SecureRandomMock(ByteFiller byteFiller) {
// this.byteFiller = byteFiller;
// }
//
// @Override
// public void nextBytes(byte[] bytes) {
// byteFiller.fill(bytes);
// }
//
// public static SecureRandomMock cycle(byte... bytes) {
// return new SecureRandomMock(new CyclicByteFiller(bytes));
// }
//
// public interface ByteFiller {
// void fill(byte[] bytes);
// }
//
// private static class CyclicByteFiller implements ByteFiller {
//
// private final Iterator<Byte> source;
//
// CyclicByteFiller(byte... bytes) {
// source = Iterators.cycle(Bytes.asList(bytes));
// }
//
// @Override
// public void fill(byte[] bytes) {
// Arrays.fill(bytes, source.next());
// }
//
// }
//
// }
// Path: src/test/java/org/cryptomator/cryptolib/v2/CryptorProviderImplTest.java
import org.cryptomator.cryptolib.api.Masterkey;
import org.cryptomator.cryptolib.common.SecureRandomMock;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import java.security.SecureRandom;
/*******************************************************************************
* Copyright (c) 2016 Sebastian Stenzel and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the accompanying LICENSE.txt.
*
* Contributors:
* Sebastian Stenzel - initial API and implementation
*******************************************************************************/
package org.cryptomator.cryptolib.v2;
public class CryptorProviderImplTest {
private static final SecureRandom RANDOM_MOCK = SecureRandomMock.NULL_RANDOM;
@Test
public void testProvide() { | Masterkey masterkey = Mockito.mock(Masterkey.class); |
cryptomator/cryptolib | src/test/java/org/cryptomator/cryptolib/v1/CryptorImplTest.java | // Path: src/main/java/org/cryptomator/cryptolib/api/Masterkey.java
// public class Masterkey extends DestroyableSecretKey {
//
// private static final String KEY_ALGORITHM = "MASTERKEY";
// public static final String ENC_ALG = "AES";
// public static final String MAC_ALG = "HmacSHA256";
// public static final int SUBKEY_LEN_BYTES = 32;
//
// public Masterkey(byte[] key) {
// super(checkKeyLength(key), KEY_ALGORITHM);
// }
//
// private static byte[] checkKeyLength(byte[] key) {
// Preconditions.checkArgument(key.length == SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES, "Invalid raw key length %s", key.length);
// return key;
// }
//
// public static Masterkey generate(SecureRandom csprng) {
// byte[] key = new byte[SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES];
// try {
// csprng.nextBytes(key);
// return new Masterkey(key);
// } finally {
// Arrays.fill(key, (byte) 0x00);
// }
// }
//
// public static Masterkey from(DestroyableSecretKey encKey, DestroyableSecretKey macKey) {
// Preconditions.checkArgument(encKey.getEncoded().length == SUBKEY_LEN_BYTES, "Invalid key length of encKey");
// Preconditions.checkArgument(macKey.getEncoded().length == SUBKEY_LEN_BYTES, "Invalid key length of macKey");
// byte[] key = new byte[SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES];
// try {
// System.arraycopy(encKey.getEncoded(), 0, key, 0, SUBKEY_LEN_BYTES);
// System.arraycopy(macKey.getEncoded(), 0, key, SUBKEY_LEN_BYTES, SUBKEY_LEN_BYTES);
// return new Masterkey(key);
// } finally {
// Arrays.fill(key, (byte) 0x00);
// }
// }
//
// @Override
// public Masterkey copy() {
// return new Masterkey(getEncoded());
// }
//
// /**
// * Get the encryption subkey.
// *
// * @return A new copy of the subkey used for encryption
// */
// public DestroyableSecretKey getEncKey() {
// return new DestroyableSecretKey(getEncoded(), 0, SUBKEY_LEN_BYTES, ENC_ALG);
// }
//
// /**
// * Get the MAC subkey.
// *
// * @return A new copy of the subkey used for message authentication
// */
// public DestroyableSecretKey getMacKey() {
// return new DestroyableSecretKey(getEncoded(), SUBKEY_LEN_BYTES, SUBKEY_LEN_BYTES, MAC_ALG);
// }
//
// }
//
// Path: src/test/java/org/cryptomator/cryptolib/common/SecureRandomMock.java
// public class SecureRandomMock extends SecureRandom {
//
// private static final ByteFiller NULL_FILLER = bytes -> Arrays.fill(bytes, (byte) 0x00);
// public static final SecureRandomMock NULL_RANDOM = new SecureRandomMock(NULL_FILLER);
// private static final ByteFiller PRNG_FILLER = new ByteFiller() {
//
// private final Random random = new Random();
//
// @Override
// public void fill(byte[] bytes) {
// random.nextBytes(bytes);
// }
//
// };
// public static final SecureRandomMock PRNG_RANDOM = new SecureRandomMock(PRNG_FILLER);
//
// private final ByteFiller byteFiller;
//
// public SecureRandomMock(ByteFiller byteFiller) {
// this.byteFiller = byteFiller;
// }
//
// @Override
// public void nextBytes(byte[] bytes) {
// byteFiller.fill(bytes);
// }
//
// public static SecureRandomMock cycle(byte... bytes) {
// return new SecureRandomMock(new CyclicByteFiller(bytes));
// }
//
// public interface ByteFiller {
// void fill(byte[] bytes);
// }
//
// private static class CyclicByteFiller implements ByteFiller {
//
// private final Iterator<Byte> source;
//
// CyclicByteFiller(byte... bytes) {
// source = Iterators.cycle(Bytes.asList(bytes));
// }
//
// @Override
// public void fill(byte[] bytes) {
// Arrays.fill(bytes, source.next());
// }
//
// }
//
// }
| import org.cryptomator.cryptolib.api.Masterkey;
import org.cryptomator.cryptolib.common.SecureRandomMock;
import org.hamcrest.CoreMatchers;
import org.hamcrest.MatcherAssert;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import java.security.SecureRandom; | /*******************************************************************************
* Copyright (c) 2016 Sebastian Stenzel and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the accompanying LICENSE.txt.
*
* Contributors:
* Sebastian Stenzel - initial API and implementation
*******************************************************************************/
package org.cryptomator.cryptolib.v1;
public class CryptorImplTest {
private static final SecureRandom RANDOM_MOCK = SecureRandomMock.NULL_RANDOM;
| // Path: src/main/java/org/cryptomator/cryptolib/api/Masterkey.java
// public class Masterkey extends DestroyableSecretKey {
//
// private static final String KEY_ALGORITHM = "MASTERKEY";
// public static final String ENC_ALG = "AES";
// public static final String MAC_ALG = "HmacSHA256";
// public static final int SUBKEY_LEN_BYTES = 32;
//
// public Masterkey(byte[] key) {
// super(checkKeyLength(key), KEY_ALGORITHM);
// }
//
// private static byte[] checkKeyLength(byte[] key) {
// Preconditions.checkArgument(key.length == SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES, "Invalid raw key length %s", key.length);
// return key;
// }
//
// public static Masterkey generate(SecureRandom csprng) {
// byte[] key = new byte[SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES];
// try {
// csprng.nextBytes(key);
// return new Masterkey(key);
// } finally {
// Arrays.fill(key, (byte) 0x00);
// }
// }
//
// public static Masterkey from(DestroyableSecretKey encKey, DestroyableSecretKey macKey) {
// Preconditions.checkArgument(encKey.getEncoded().length == SUBKEY_LEN_BYTES, "Invalid key length of encKey");
// Preconditions.checkArgument(macKey.getEncoded().length == SUBKEY_LEN_BYTES, "Invalid key length of macKey");
// byte[] key = new byte[SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES];
// try {
// System.arraycopy(encKey.getEncoded(), 0, key, 0, SUBKEY_LEN_BYTES);
// System.arraycopy(macKey.getEncoded(), 0, key, SUBKEY_LEN_BYTES, SUBKEY_LEN_BYTES);
// return new Masterkey(key);
// } finally {
// Arrays.fill(key, (byte) 0x00);
// }
// }
//
// @Override
// public Masterkey copy() {
// return new Masterkey(getEncoded());
// }
//
// /**
// * Get the encryption subkey.
// *
// * @return A new copy of the subkey used for encryption
// */
// public DestroyableSecretKey getEncKey() {
// return new DestroyableSecretKey(getEncoded(), 0, SUBKEY_LEN_BYTES, ENC_ALG);
// }
//
// /**
// * Get the MAC subkey.
// *
// * @return A new copy of the subkey used for message authentication
// */
// public DestroyableSecretKey getMacKey() {
// return new DestroyableSecretKey(getEncoded(), SUBKEY_LEN_BYTES, SUBKEY_LEN_BYTES, MAC_ALG);
// }
//
// }
//
// Path: src/test/java/org/cryptomator/cryptolib/common/SecureRandomMock.java
// public class SecureRandomMock extends SecureRandom {
//
// private static final ByteFiller NULL_FILLER = bytes -> Arrays.fill(bytes, (byte) 0x00);
// public static final SecureRandomMock NULL_RANDOM = new SecureRandomMock(NULL_FILLER);
// private static final ByteFiller PRNG_FILLER = new ByteFiller() {
//
// private final Random random = new Random();
//
// @Override
// public void fill(byte[] bytes) {
// random.nextBytes(bytes);
// }
//
// };
// public static final SecureRandomMock PRNG_RANDOM = new SecureRandomMock(PRNG_FILLER);
//
// private final ByteFiller byteFiller;
//
// public SecureRandomMock(ByteFiller byteFiller) {
// this.byteFiller = byteFiller;
// }
//
// @Override
// public void nextBytes(byte[] bytes) {
// byteFiller.fill(bytes);
// }
//
// public static SecureRandomMock cycle(byte... bytes) {
// return new SecureRandomMock(new CyclicByteFiller(bytes));
// }
//
// public interface ByteFiller {
// void fill(byte[] bytes);
// }
//
// private static class CyclicByteFiller implements ByteFiller {
//
// private final Iterator<Byte> source;
//
// CyclicByteFiller(byte... bytes) {
// source = Iterators.cycle(Bytes.asList(bytes));
// }
//
// @Override
// public void fill(byte[] bytes) {
// Arrays.fill(bytes, source.next());
// }
//
// }
//
// }
// Path: src/test/java/org/cryptomator/cryptolib/v1/CryptorImplTest.java
import org.cryptomator.cryptolib.api.Masterkey;
import org.cryptomator.cryptolib.common.SecureRandomMock;
import org.hamcrest.CoreMatchers;
import org.hamcrest.MatcherAssert;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import java.security.SecureRandom;
/*******************************************************************************
* Copyright (c) 2016 Sebastian Stenzel and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the accompanying LICENSE.txt.
*
* Contributors:
* Sebastian Stenzel - initial API and implementation
*******************************************************************************/
package org.cryptomator.cryptolib.v1;
public class CryptorImplTest {
private static final SecureRandom RANDOM_MOCK = SecureRandomMock.NULL_RANDOM;
| private Masterkey masterkey; |
cryptomator/cryptolib | src/main/java/org/cryptomator/cryptolib/common/DecryptingReadableByteChannel.java | // Path: src/main/java/org/cryptomator/cryptolib/api/AuthenticationFailedException.java
// public class AuthenticationFailedException extends CryptoException {
//
// public AuthenticationFailedException(String message) {
// super(message);
// }
//
// public AuthenticationFailedException(String message, Throwable cause) {
// super(message, cause);
// }
//
// }
//
// Path: src/main/java/org/cryptomator/cryptolib/api/Cryptor.java
// public interface Cryptor extends Destroyable, AutoCloseable {
//
// FileContentCryptor fileContentCryptor();
//
// FileHeaderCryptor fileHeaderCryptor();
//
// FileNameCryptor fileNameCryptor();
//
// @Override
// void destroy();
//
// /**
// * Calls {@link #destroy()}.
// */
// @Override
// default void close() {
// destroy();
// }
//
// }
//
// Path: src/main/java/org/cryptomator/cryptolib/api/FileHeader.java
// public interface FileHeader {
//
// /**
// * Returns the value of a currently unused 64 bit field in the file header.
// * <p>
// * Formerly used for storing the plaintext file size.
// *
// * @return 64 bit integer for future use.
// * @deprecated Don't rely on this method. It may be redefined any time.
// */
// @Deprecated
// long getReserved();
//
// /**
// * Sets the 64 bit field in the file header.
// * <p>
// * Formerly used for storing the plaintext file size.
// *
// * @param reserved 64 bit integer for future use
// * @deprecated Don't rely on this method. It may be redefined any time.
// */
// @Deprecated
// void setReserved(long reserved);
//
// }
| import org.cryptomator.cryptolib.api.AuthenticationFailedException;
import org.cryptomator.cryptolib.api.Cryptor;
import org.cryptomator.cryptolib.api.FileHeader;
import java.io.EOFException;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.ReadableByteChannel; | /*******************************************************************************
* Copyright (c) 2016 Sebastian Stenzel and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the accompanying LICENSE.txt.
*
* Contributors:
* Sebastian Stenzel - initial API and implementation
*******************************************************************************/
package org.cryptomator.cryptolib.common;
public class DecryptingReadableByteChannel implements ReadableByteChannel {
private final ReadableByteChannel delegate; | // Path: src/main/java/org/cryptomator/cryptolib/api/AuthenticationFailedException.java
// public class AuthenticationFailedException extends CryptoException {
//
// public AuthenticationFailedException(String message) {
// super(message);
// }
//
// public AuthenticationFailedException(String message, Throwable cause) {
// super(message, cause);
// }
//
// }
//
// Path: src/main/java/org/cryptomator/cryptolib/api/Cryptor.java
// public interface Cryptor extends Destroyable, AutoCloseable {
//
// FileContentCryptor fileContentCryptor();
//
// FileHeaderCryptor fileHeaderCryptor();
//
// FileNameCryptor fileNameCryptor();
//
// @Override
// void destroy();
//
// /**
// * Calls {@link #destroy()}.
// */
// @Override
// default void close() {
// destroy();
// }
//
// }
//
// Path: src/main/java/org/cryptomator/cryptolib/api/FileHeader.java
// public interface FileHeader {
//
// /**
// * Returns the value of a currently unused 64 bit field in the file header.
// * <p>
// * Formerly used for storing the plaintext file size.
// *
// * @return 64 bit integer for future use.
// * @deprecated Don't rely on this method. It may be redefined any time.
// */
// @Deprecated
// long getReserved();
//
// /**
// * Sets the 64 bit field in the file header.
// * <p>
// * Formerly used for storing the plaintext file size.
// *
// * @param reserved 64 bit integer for future use
// * @deprecated Don't rely on this method. It may be redefined any time.
// */
// @Deprecated
// void setReserved(long reserved);
//
// }
// Path: src/main/java/org/cryptomator/cryptolib/common/DecryptingReadableByteChannel.java
import org.cryptomator.cryptolib.api.AuthenticationFailedException;
import org.cryptomator.cryptolib.api.Cryptor;
import org.cryptomator.cryptolib.api.FileHeader;
import java.io.EOFException;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.ReadableByteChannel;
/*******************************************************************************
* Copyright (c) 2016 Sebastian Stenzel and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the accompanying LICENSE.txt.
*
* Contributors:
* Sebastian Stenzel - initial API and implementation
*******************************************************************************/
package org.cryptomator.cryptolib.common;
public class DecryptingReadableByteChannel implements ReadableByteChannel {
private final ReadableByteChannel delegate; | private final Cryptor cryptor; |
cryptomator/cryptolib | src/main/java/org/cryptomator/cryptolib/common/DecryptingReadableByteChannel.java | // Path: src/main/java/org/cryptomator/cryptolib/api/AuthenticationFailedException.java
// public class AuthenticationFailedException extends CryptoException {
//
// public AuthenticationFailedException(String message) {
// super(message);
// }
//
// public AuthenticationFailedException(String message, Throwable cause) {
// super(message, cause);
// }
//
// }
//
// Path: src/main/java/org/cryptomator/cryptolib/api/Cryptor.java
// public interface Cryptor extends Destroyable, AutoCloseable {
//
// FileContentCryptor fileContentCryptor();
//
// FileHeaderCryptor fileHeaderCryptor();
//
// FileNameCryptor fileNameCryptor();
//
// @Override
// void destroy();
//
// /**
// * Calls {@link #destroy()}.
// */
// @Override
// default void close() {
// destroy();
// }
//
// }
//
// Path: src/main/java/org/cryptomator/cryptolib/api/FileHeader.java
// public interface FileHeader {
//
// /**
// * Returns the value of a currently unused 64 bit field in the file header.
// * <p>
// * Formerly used for storing the plaintext file size.
// *
// * @return 64 bit integer for future use.
// * @deprecated Don't rely on this method. It may be redefined any time.
// */
// @Deprecated
// long getReserved();
//
// /**
// * Sets the 64 bit field in the file header.
// * <p>
// * Formerly used for storing the plaintext file size.
// *
// * @param reserved 64 bit integer for future use
// * @deprecated Don't rely on this method. It may be redefined any time.
// */
// @Deprecated
// void setReserved(long reserved);
//
// }
| import org.cryptomator.cryptolib.api.AuthenticationFailedException;
import org.cryptomator.cryptolib.api.Cryptor;
import org.cryptomator.cryptolib.api.FileHeader;
import java.io.EOFException;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.ReadableByteChannel; | /*******************************************************************************
* Copyright (c) 2016 Sebastian Stenzel and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the accompanying LICENSE.txt.
*
* Contributors:
* Sebastian Stenzel - initial API and implementation
*******************************************************************************/
package org.cryptomator.cryptolib.common;
public class DecryptingReadableByteChannel implements ReadableByteChannel {
private final ReadableByteChannel delegate;
private final Cryptor cryptor;
private final boolean authenticate;
private ByteBuffer cleartextChunk; | // Path: src/main/java/org/cryptomator/cryptolib/api/AuthenticationFailedException.java
// public class AuthenticationFailedException extends CryptoException {
//
// public AuthenticationFailedException(String message) {
// super(message);
// }
//
// public AuthenticationFailedException(String message, Throwable cause) {
// super(message, cause);
// }
//
// }
//
// Path: src/main/java/org/cryptomator/cryptolib/api/Cryptor.java
// public interface Cryptor extends Destroyable, AutoCloseable {
//
// FileContentCryptor fileContentCryptor();
//
// FileHeaderCryptor fileHeaderCryptor();
//
// FileNameCryptor fileNameCryptor();
//
// @Override
// void destroy();
//
// /**
// * Calls {@link #destroy()}.
// */
// @Override
// default void close() {
// destroy();
// }
//
// }
//
// Path: src/main/java/org/cryptomator/cryptolib/api/FileHeader.java
// public interface FileHeader {
//
// /**
// * Returns the value of a currently unused 64 bit field in the file header.
// * <p>
// * Formerly used for storing the plaintext file size.
// *
// * @return 64 bit integer for future use.
// * @deprecated Don't rely on this method. It may be redefined any time.
// */
// @Deprecated
// long getReserved();
//
// /**
// * Sets the 64 bit field in the file header.
// * <p>
// * Formerly used for storing the plaintext file size.
// *
// * @param reserved 64 bit integer for future use
// * @deprecated Don't rely on this method. It may be redefined any time.
// */
// @Deprecated
// void setReserved(long reserved);
//
// }
// Path: src/main/java/org/cryptomator/cryptolib/common/DecryptingReadableByteChannel.java
import org.cryptomator.cryptolib.api.AuthenticationFailedException;
import org.cryptomator.cryptolib.api.Cryptor;
import org.cryptomator.cryptolib.api.FileHeader;
import java.io.EOFException;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.ReadableByteChannel;
/*******************************************************************************
* Copyright (c) 2016 Sebastian Stenzel and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the accompanying LICENSE.txt.
*
* Contributors:
* Sebastian Stenzel - initial API and implementation
*******************************************************************************/
package org.cryptomator.cryptolib.common;
public class DecryptingReadableByteChannel implements ReadableByteChannel {
private final ReadableByteChannel delegate;
private final Cryptor cryptor;
private final boolean authenticate;
private ByteBuffer cleartextChunk; | private FileHeader header; |
cryptomator/cryptolib | src/main/java/org/cryptomator/cryptolib/common/DecryptingReadableByteChannel.java | // Path: src/main/java/org/cryptomator/cryptolib/api/AuthenticationFailedException.java
// public class AuthenticationFailedException extends CryptoException {
//
// public AuthenticationFailedException(String message) {
// super(message);
// }
//
// public AuthenticationFailedException(String message, Throwable cause) {
// super(message, cause);
// }
//
// }
//
// Path: src/main/java/org/cryptomator/cryptolib/api/Cryptor.java
// public interface Cryptor extends Destroyable, AutoCloseable {
//
// FileContentCryptor fileContentCryptor();
//
// FileHeaderCryptor fileHeaderCryptor();
//
// FileNameCryptor fileNameCryptor();
//
// @Override
// void destroy();
//
// /**
// * Calls {@link #destroy()}.
// */
// @Override
// default void close() {
// destroy();
// }
//
// }
//
// Path: src/main/java/org/cryptomator/cryptolib/api/FileHeader.java
// public interface FileHeader {
//
// /**
// * Returns the value of a currently unused 64 bit field in the file header.
// * <p>
// * Formerly used for storing the plaintext file size.
// *
// * @return 64 bit integer for future use.
// * @deprecated Don't rely on this method. It may be redefined any time.
// */
// @Deprecated
// long getReserved();
//
// /**
// * Sets the 64 bit field in the file header.
// * <p>
// * Formerly used for storing the plaintext file size.
// *
// * @param reserved 64 bit integer for future use
// * @deprecated Don't rely on this method. It may be redefined any time.
// */
// @Deprecated
// void setReserved(long reserved);
//
// }
| import org.cryptomator.cryptolib.api.AuthenticationFailedException;
import org.cryptomator.cryptolib.api.Cryptor;
import org.cryptomator.cryptolib.api.FileHeader;
import java.io.EOFException;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.ReadableByteChannel; | */
public DecryptingReadableByteChannel(ReadableByteChannel src, Cryptor cryptor, boolean authenticate, FileHeader header, long firstChunk) {
this.delegate = src;
this.cryptor = cryptor;
this.authenticate = authenticate;
this.cleartextChunk = ByteBuffer.allocate(0); // empty buffer will trigger loadNextCleartextChunk() on first access.
this.header = header;
this.reachedEof = false;
this.chunk = firstChunk;
}
@Override
public boolean isOpen() {
return delegate.isOpen();
}
@Override
public void close() throws IOException {
delegate.close();
}
@Override
public synchronized int read(ByteBuffer dst) throws IOException {
try {
loadHeaderIfNecessary();
if (reachedEof) {
return -1;
} else {
return readInternal(dst);
} | // Path: src/main/java/org/cryptomator/cryptolib/api/AuthenticationFailedException.java
// public class AuthenticationFailedException extends CryptoException {
//
// public AuthenticationFailedException(String message) {
// super(message);
// }
//
// public AuthenticationFailedException(String message, Throwable cause) {
// super(message, cause);
// }
//
// }
//
// Path: src/main/java/org/cryptomator/cryptolib/api/Cryptor.java
// public interface Cryptor extends Destroyable, AutoCloseable {
//
// FileContentCryptor fileContentCryptor();
//
// FileHeaderCryptor fileHeaderCryptor();
//
// FileNameCryptor fileNameCryptor();
//
// @Override
// void destroy();
//
// /**
// * Calls {@link #destroy()}.
// */
// @Override
// default void close() {
// destroy();
// }
//
// }
//
// Path: src/main/java/org/cryptomator/cryptolib/api/FileHeader.java
// public interface FileHeader {
//
// /**
// * Returns the value of a currently unused 64 bit field in the file header.
// * <p>
// * Formerly used for storing the plaintext file size.
// *
// * @return 64 bit integer for future use.
// * @deprecated Don't rely on this method. It may be redefined any time.
// */
// @Deprecated
// long getReserved();
//
// /**
// * Sets the 64 bit field in the file header.
// * <p>
// * Formerly used for storing the plaintext file size.
// *
// * @param reserved 64 bit integer for future use
// * @deprecated Don't rely on this method. It may be redefined any time.
// */
// @Deprecated
// void setReserved(long reserved);
//
// }
// Path: src/main/java/org/cryptomator/cryptolib/common/DecryptingReadableByteChannel.java
import org.cryptomator.cryptolib.api.AuthenticationFailedException;
import org.cryptomator.cryptolib.api.Cryptor;
import org.cryptomator.cryptolib.api.FileHeader;
import java.io.EOFException;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.ReadableByteChannel;
*/
public DecryptingReadableByteChannel(ReadableByteChannel src, Cryptor cryptor, boolean authenticate, FileHeader header, long firstChunk) {
this.delegate = src;
this.cryptor = cryptor;
this.authenticate = authenticate;
this.cleartextChunk = ByteBuffer.allocate(0); // empty buffer will trigger loadNextCleartextChunk() on first access.
this.header = header;
this.reachedEof = false;
this.chunk = firstChunk;
}
@Override
public boolean isOpen() {
return delegate.isOpen();
}
@Override
public void close() throws IOException {
delegate.close();
}
@Override
public synchronized int read(ByteBuffer dst) throws IOException {
try {
loadHeaderIfNecessary();
if (reachedEof) {
return -1;
} else {
return readInternal(dst);
} | } catch (AuthenticationFailedException e) { |
cryptomator/cryptolib | src/test/java/org/cryptomator/cryptolib/v1/CryptorProviderImplTest.java | // Path: src/main/java/org/cryptomator/cryptolib/api/Masterkey.java
// public class Masterkey extends DestroyableSecretKey {
//
// private static final String KEY_ALGORITHM = "MASTERKEY";
// public static final String ENC_ALG = "AES";
// public static final String MAC_ALG = "HmacSHA256";
// public static final int SUBKEY_LEN_BYTES = 32;
//
// public Masterkey(byte[] key) {
// super(checkKeyLength(key), KEY_ALGORITHM);
// }
//
// private static byte[] checkKeyLength(byte[] key) {
// Preconditions.checkArgument(key.length == SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES, "Invalid raw key length %s", key.length);
// return key;
// }
//
// public static Masterkey generate(SecureRandom csprng) {
// byte[] key = new byte[SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES];
// try {
// csprng.nextBytes(key);
// return new Masterkey(key);
// } finally {
// Arrays.fill(key, (byte) 0x00);
// }
// }
//
// public static Masterkey from(DestroyableSecretKey encKey, DestroyableSecretKey macKey) {
// Preconditions.checkArgument(encKey.getEncoded().length == SUBKEY_LEN_BYTES, "Invalid key length of encKey");
// Preconditions.checkArgument(macKey.getEncoded().length == SUBKEY_LEN_BYTES, "Invalid key length of macKey");
// byte[] key = new byte[SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES];
// try {
// System.arraycopy(encKey.getEncoded(), 0, key, 0, SUBKEY_LEN_BYTES);
// System.arraycopy(macKey.getEncoded(), 0, key, SUBKEY_LEN_BYTES, SUBKEY_LEN_BYTES);
// return new Masterkey(key);
// } finally {
// Arrays.fill(key, (byte) 0x00);
// }
// }
//
// @Override
// public Masterkey copy() {
// return new Masterkey(getEncoded());
// }
//
// /**
// * Get the encryption subkey.
// *
// * @return A new copy of the subkey used for encryption
// */
// public DestroyableSecretKey getEncKey() {
// return new DestroyableSecretKey(getEncoded(), 0, SUBKEY_LEN_BYTES, ENC_ALG);
// }
//
// /**
// * Get the MAC subkey.
// *
// * @return A new copy of the subkey used for message authentication
// */
// public DestroyableSecretKey getMacKey() {
// return new DestroyableSecretKey(getEncoded(), SUBKEY_LEN_BYTES, SUBKEY_LEN_BYTES, MAC_ALG);
// }
//
// }
//
// Path: src/test/java/org/cryptomator/cryptolib/common/SecureRandomMock.java
// public class SecureRandomMock extends SecureRandom {
//
// private static final ByteFiller NULL_FILLER = bytes -> Arrays.fill(bytes, (byte) 0x00);
// public static final SecureRandomMock NULL_RANDOM = new SecureRandomMock(NULL_FILLER);
// private static final ByteFiller PRNG_FILLER = new ByteFiller() {
//
// private final Random random = new Random();
//
// @Override
// public void fill(byte[] bytes) {
// random.nextBytes(bytes);
// }
//
// };
// public static final SecureRandomMock PRNG_RANDOM = new SecureRandomMock(PRNG_FILLER);
//
// private final ByteFiller byteFiller;
//
// public SecureRandomMock(ByteFiller byteFiller) {
// this.byteFiller = byteFiller;
// }
//
// @Override
// public void nextBytes(byte[] bytes) {
// byteFiller.fill(bytes);
// }
//
// public static SecureRandomMock cycle(byte... bytes) {
// return new SecureRandomMock(new CyclicByteFiller(bytes));
// }
//
// public interface ByteFiller {
// void fill(byte[] bytes);
// }
//
// private static class CyclicByteFiller implements ByteFiller {
//
// private final Iterator<Byte> source;
//
// CyclicByteFiller(byte... bytes) {
// source = Iterators.cycle(Bytes.asList(bytes));
// }
//
// @Override
// public void fill(byte[] bytes) {
// Arrays.fill(bytes, source.next());
// }
//
// }
//
// }
| import org.cryptomator.cryptolib.api.Masterkey;
import org.cryptomator.cryptolib.common.SecureRandomMock;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import java.security.SecureRandom; | /*******************************************************************************
* Copyright (c) 2016 Sebastian Stenzel and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the accompanying LICENSE.txt.
*
* Contributors:
* Sebastian Stenzel - initial API and implementation
*******************************************************************************/
package org.cryptomator.cryptolib.v1;
public class CryptorProviderImplTest {
private static final SecureRandom RANDOM_MOCK = SecureRandomMock.NULL_RANDOM;
@Test
public void testProvide() { | // Path: src/main/java/org/cryptomator/cryptolib/api/Masterkey.java
// public class Masterkey extends DestroyableSecretKey {
//
// private static final String KEY_ALGORITHM = "MASTERKEY";
// public static final String ENC_ALG = "AES";
// public static final String MAC_ALG = "HmacSHA256";
// public static final int SUBKEY_LEN_BYTES = 32;
//
// public Masterkey(byte[] key) {
// super(checkKeyLength(key), KEY_ALGORITHM);
// }
//
// private static byte[] checkKeyLength(byte[] key) {
// Preconditions.checkArgument(key.length == SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES, "Invalid raw key length %s", key.length);
// return key;
// }
//
// public static Masterkey generate(SecureRandom csprng) {
// byte[] key = new byte[SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES];
// try {
// csprng.nextBytes(key);
// return new Masterkey(key);
// } finally {
// Arrays.fill(key, (byte) 0x00);
// }
// }
//
// public static Masterkey from(DestroyableSecretKey encKey, DestroyableSecretKey macKey) {
// Preconditions.checkArgument(encKey.getEncoded().length == SUBKEY_LEN_BYTES, "Invalid key length of encKey");
// Preconditions.checkArgument(macKey.getEncoded().length == SUBKEY_LEN_BYTES, "Invalid key length of macKey");
// byte[] key = new byte[SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES];
// try {
// System.arraycopy(encKey.getEncoded(), 0, key, 0, SUBKEY_LEN_BYTES);
// System.arraycopy(macKey.getEncoded(), 0, key, SUBKEY_LEN_BYTES, SUBKEY_LEN_BYTES);
// return new Masterkey(key);
// } finally {
// Arrays.fill(key, (byte) 0x00);
// }
// }
//
// @Override
// public Masterkey copy() {
// return new Masterkey(getEncoded());
// }
//
// /**
// * Get the encryption subkey.
// *
// * @return A new copy of the subkey used for encryption
// */
// public DestroyableSecretKey getEncKey() {
// return new DestroyableSecretKey(getEncoded(), 0, SUBKEY_LEN_BYTES, ENC_ALG);
// }
//
// /**
// * Get the MAC subkey.
// *
// * @return A new copy of the subkey used for message authentication
// */
// public DestroyableSecretKey getMacKey() {
// return new DestroyableSecretKey(getEncoded(), SUBKEY_LEN_BYTES, SUBKEY_LEN_BYTES, MAC_ALG);
// }
//
// }
//
// Path: src/test/java/org/cryptomator/cryptolib/common/SecureRandomMock.java
// public class SecureRandomMock extends SecureRandom {
//
// private static final ByteFiller NULL_FILLER = bytes -> Arrays.fill(bytes, (byte) 0x00);
// public static final SecureRandomMock NULL_RANDOM = new SecureRandomMock(NULL_FILLER);
// private static final ByteFiller PRNG_FILLER = new ByteFiller() {
//
// private final Random random = new Random();
//
// @Override
// public void fill(byte[] bytes) {
// random.nextBytes(bytes);
// }
//
// };
// public static final SecureRandomMock PRNG_RANDOM = new SecureRandomMock(PRNG_FILLER);
//
// private final ByteFiller byteFiller;
//
// public SecureRandomMock(ByteFiller byteFiller) {
// this.byteFiller = byteFiller;
// }
//
// @Override
// public void nextBytes(byte[] bytes) {
// byteFiller.fill(bytes);
// }
//
// public static SecureRandomMock cycle(byte... bytes) {
// return new SecureRandomMock(new CyclicByteFiller(bytes));
// }
//
// public interface ByteFiller {
// void fill(byte[] bytes);
// }
//
// private static class CyclicByteFiller implements ByteFiller {
//
// private final Iterator<Byte> source;
//
// CyclicByteFiller(byte... bytes) {
// source = Iterators.cycle(Bytes.asList(bytes));
// }
//
// @Override
// public void fill(byte[] bytes) {
// Arrays.fill(bytes, source.next());
// }
//
// }
//
// }
// Path: src/test/java/org/cryptomator/cryptolib/v1/CryptorProviderImplTest.java
import org.cryptomator.cryptolib.api.Masterkey;
import org.cryptomator.cryptolib.common.SecureRandomMock;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import java.security.SecureRandom;
/*******************************************************************************
* Copyright (c) 2016 Sebastian Stenzel and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the accompanying LICENSE.txt.
*
* Contributors:
* Sebastian Stenzel - initial API and implementation
*******************************************************************************/
package org.cryptomator.cryptolib.v1;
public class CryptorProviderImplTest {
private static final SecureRandom RANDOM_MOCK = SecureRandomMock.NULL_RANDOM;
@Test
public void testProvide() { | Masterkey masterkey = Mockito.mock(Masterkey.class); |
cryptomator/cryptolib | src/test/java/org/cryptomator/cryptolib/v2/CryptorImplTest.java | // Path: src/main/java/org/cryptomator/cryptolib/api/Masterkey.java
// public class Masterkey extends DestroyableSecretKey {
//
// private static final String KEY_ALGORITHM = "MASTERKEY";
// public static final String ENC_ALG = "AES";
// public static final String MAC_ALG = "HmacSHA256";
// public static final int SUBKEY_LEN_BYTES = 32;
//
// public Masterkey(byte[] key) {
// super(checkKeyLength(key), KEY_ALGORITHM);
// }
//
// private static byte[] checkKeyLength(byte[] key) {
// Preconditions.checkArgument(key.length == SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES, "Invalid raw key length %s", key.length);
// return key;
// }
//
// public static Masterkey generate(SecureRandom csprng) {
// byte[] key = new byte[SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES];
// try {
// csprng.nextBytes(key);
// return new Masterkey(key);
// } finally {
// Arrays.fill(key, (byte) 0x00);
// }
// }
//
// public static Masterkey from(DestroyableSecretKey encKey, DestroyableSecretKey macKey) {
// Preconditions.checkArgument(encKey.getEncoded().length == SUBKEY_LEN_BYTES, "Invalid key length of encKey");
// Preconditions.checkArgument(macKey.getEncoded().length == SUBKEY_LEN_BYTES, "Invalid key length of macKey");
// byte[] key = new byte[SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES];
// try {
// System.arraycopy(encKey.getEncoded(), 0, key, 0, SUBKEY_LEN_BYTES);
// System.arraycopy(macKey.getEncoded(), 0, key, SUBKEY_LEN_BYTES, SUBKEY_LEN_BYTES);
// return new Masterkey(key);
// } finally {
// Arrays.fill(key, (byte) 0x00);
// }
// }
//
// @Override
// public Masterkey copy() {
// return new Masterkey(getEncoded());
// }
//
// /**
// * Get the encryption subkey.
// *
// * @return A new copy of the subkey used for encryption
// */
// public DestroyableSecretKey getEncKey() {
// return new DestroyableSecretKey(getEncoded(), 0, SUBKEY_LEN_BYTES, ENC_ALG);
// }
//
// /**
// * Get the MAC subkey.
// *
// * @return A new copy of the subkey used for message authentication
// */
// public DestroyableSecretKey getMacKey() {
// return new DestroyableSecretKey(getEncoded(), SUBKEY_LEN_BYTES, SUBKEY_LEN_BYTES, MAC_ALG);
// }
//
// }
//
// Path: src/test/java/org/cryptomator/cryptolib/common/SecureRandomMock.java
// public class SecureRandomMock extends SecureRandom {
//
// private static final ByteFiller NULL_FILLER = bytes -> Arrays.fill(bytes, (byte) 0x00);
// public static final SecureRandomMock NULL_RANDOM = new SecureRandomMock(NULL_FILLER);
// private static final ByteFiller PRNG_FILLER = new ByteFiller() {
//
// private final Random random = new Random();
//
// @Override
// public void fill(byte[] bytes) {
// random.nextBytes(bytes);
// }
//
// };
// public static final SecureRandomMock PRNG_RANDOM = new SecureRandomMock(PRNG_FILLER);
//
// private final ByteFiller byteFiller;
//
// public SecureRandomMock(ByteFiller byteFiller) {
// this.byteFiller = byteFiller;
// }
//
// @Override
// public void nextBytes(byte[] bytes) {
// byteFiller.fill(bytes);
// }
//
// public static SecureRandomMock cycle(byte... bytes) {
// return new SecureRandomMock(new CyclicByteFiller(bytes));
// }
//
// public interface ByteFiller {
// void fill(byte[] bytes);
// }
//
// private static class CyclicByteFiller implements ByteFiller {
//
// private final Iterator<Byte> source;
//
// CyclicByteFiller(byte... bytes) {
// source = Iterators.cycle(Bytes.asList(bytes));
// }
//
// @Override
// public void fill(byte[] bytes) {
// Arrays.fill(bytes, source.next());
// }
//
// }
//
// }
| import org.cryptomator.cryptolib.api.Masterkey;
import org.cryptomator.cryptolib.common.SecureRandomMock;
import org.hamcrest.CoreMatchers;
import org.hamcrest.MatcherAssert;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import java.security.SecureRandom; | /*******************************************************************************
* Copyright (c) 2016 Sebastian Stenzel and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the accompanying LICENSE.txt.
*
* Contributors:
* Sebastian Stenzel - initial API and implementation
*******************************************************************************/
package org.cryptomator.cryptolib.v2;
public class CryptorImplTest {
private static final SecureRandom RANDOM_MOCK = SecureRandomMock.NULL_RANDOM;
| // Path: src/main/java/org/cryptomator/cryptolib/api/Masterkey.java
// public class Masterkey extends DestroyableSecretKey {
//
// private static final String KEY_ALGORITHM = "MASTERKEY";
// public static final String ENC_ALG = "AES";
// public static final String MAC_ALG = "HmacSHA256";
// public static final int SUBKEY_LEN_BYTES = 32;
//
// public Masterkey(byte[] key) {
// super(checkKeyLength(key), KEY_ALGORITHM);
// }
//
// private static byte[] checkKeyLength(byte[] key) {
// Preconditions.checkArgument(key.length == SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES, "Invalid raw key length %s", key.length);
// return key;
// }
//
// public static Masterkey generate(SecureRandom csprng) {
// byte[] key = new byte[SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES];
// try {
// csprng.nextBytes(key);
// return new Masterkey(key);
// } finally {
// Arrays.fill(key, (byte) 0x00);
// }
// }
//
// public static Masterkey from(DestroyableSecretKey encKey, DestroyableSecretKey macKey) {
// Preconditions.checkArgument(encKey.getEncoded().length == SUBKEY_LEN_BYTES, "Invalid key length of encKey");
// Preconditions.checkArgument(macKey.getEncoded().length == SUBKEY_LEN_BYTES, "Invalid key length of macKey");
// byte[] key = new byte[SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES];
// try {
// System.arraycopy(encKey.getEncoded(), 0, key, 0, SUBKEY_LEN_BYTES);
// System.arraycopy(macKey.getEncoded(), 0, key, SUBKEY_LEN_BYTES, SUBKEY_LEN_BYTES);
// return new Masterkey(key);
// } finally {
// Arrays.fill(key, (byte) 0x00);
// }
// }
//
// @Override
// public Masterkey copy() {
// return new Masterkey(getEncoded());
// }
//
// /**
// * Get the encryption subkey.
// *
// * @return A new copy of the subkey used for encryption
// */
// public DestroyableSecretKey getEncKey() {
// return new DestroyableSecretKey(getEncoded(), 0, SUBKEY_LEN_BYTES, ENC_ALG);
// }
//
// /**
// * Get the MAC subkey.
// *
// * @return A new copy of the subkey used for message authentication
// */
// public DestroyableSecretKey getMacKey() {
// return new DestroyableSecretKey(getEncoded(), SUBKEY_LEN_BYTES, SUBKEY_LEN_BYTES, MAC_ALG);
// }
//
// }
//
// Path: src/test/java/org/cryptomator/cryptolib/common/SecureRandomMock.java
// public class SecureRandomMock extends SecureRandom {
//
// private static final ByteFiller NULL_FILLER = bytes -> Arrays.fill(bytes, (byte) 0x00);
// public static final SecureRandomMock NULL_RANDOM = new SecureRandomMock(NULL_FILLER);
// private static final ByteFiller PRNG_FILLER = new ByteFiller() {
//
// private final Random random = new Random();
//
// @Override
// public void fill(byte[] bytes) {
// random.nextBytes(bytes);
// }
//
// };
// public static final SecureRandomMock PRNG_RANDOM = new SecureRandomMock(PRNG_FILLER);
//
// private final ByteFiller byteFiller;
//
// public SecureRandomMock(ByteFiller byteFiller) {
// this.byteFiller = byteFiller;
// }
//
// @Override
// public void nextBytes(byte[] bytes) {
// byteFiller.fill(bytes);
// }
//
// public static SecureRandomMock cycle(byte... bytes) {
// return new SecureRandomMock(new CyclicByteFiller(bytes));
// }
//
// public interface ByteFiller {
// void fill(byte[] bytes);
// }
//
// private static class CyclicByteFiller implements ByteFiller {
//
// private final Iterator<Byte> source;
//
// CyclicByteFiller(byte... bytes) {
// source = Iterators.cycle(Bytes.asList(bytes));
// }
//
// @Override
// public void fill(byte[] bytes) {
// Arrays.fill(bytes, source.next());
// }
//
// }
//
// }
// Path: src/test/java/org/cryptomator/cryptolib/v2/CryptorImplTest.java
import org.cryptomator.cryptolib.api.Masterkey;
import org.cryptomator.cryptolib.common.SecureRandomMock;
import org.hamcrest.CoreMatchers;
import org.hamcrest.MatcherAssert;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import java.security.SecureRandom;
/*******************************************************************************
* Copyright (c) 2016 Sebastian Stenzel and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the accompanying LICENSE.txt.
*
* Contributors:
* Sebastian Stenzel - initial API and implementation
*******************************************************************************/
package org.cryptomator.cryptolib.v2;
public class CryptorImplTest {
private static final SecureRandom RANDOM_MOCK = SecureRandomMock.NULL_RANDOM;
| private Masterkey masterkey; |
cryptomator/cryptolib | src/test/java/org/cryptomator/cryptolib/v1/FileNameCryptorImplTest.java | // Path: src/main/java/org/cryptomator/cryptolib/api/AuthenticationFailedException.java
// public class AuthenticationFailedException extends CryptoException {
//
// public AuthenticationFailedException(String message) {
// super(message);
// }
//
// public AuthenticationFailedException(String message, Throwable cause) {
// super(message, cause);
// }
//
// }
//
// Path: src/main/java/org/cryptomator/cryptolib/api/Masterkey.java
// public class Masterkey extends DestroyableSecretKey {
//
// private static final String KEY_ALGORITHM = "MASTERKEY";
// public static final String ENC_ALG = "AES";
// public static final String MAC_ALG = "HmacSHA256";
// public static final int SUBKEY_LEN_BYTES = 32;
//
// public Masterkey(byte[] key) {
// super(checkKeyLength(key), KEY_ALGORITHM);
// }
//
// private static byte[] checkKeyLength(byte[] key) {
// Preconditions.checkArgument(key.length == SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES, "Invalid raw key length %s", key.length);
// return key;
// }
//
// public static Masterkey generate(SecureRandom csprng) {
// byte[] key = new byte[SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES];
// try {
// csprng.nextBytes(key);
// return new Masterkey(key);
// } finally {
// Arrays.fill(key, (byte) 0x00);
// }
// }
//
// public static Masterkey from(DestroyableSecretKey encKey, DestroyableSecretKey macKey) {
// Preconditions.checkArgument(encKey.getEncoded().length == SUBKEY_LEN_BYTES, "Invalid key length of encKey");
// Preconditions.checkArgument(macKey.getEncoded().length == SUBKEY_LEN_BYTES, "Invalid key length of macKey");
// byte[] key = new byte[SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES];
// try {
// System.arraycopy(encKey.getEncoded(), 0, key, 0, SUBKEY_LEN_BYTES);
// System.arraycopy(macKey.getEncoded(), 0, key, SUBKEY_LEN_BYTES, SUBKEY_LEN_BYTES);
// return new Masterkey(key);
// } finally {
// Arrays.fill(key, (byte) 0x00);
// }
// }
//
// @Override
// public Masterkey copy() {
// return new Masterkey(getEncoded());
// }
//
// /**
// * Get the encryption subkey.
// *
// * @return A new copy of the subkey used for encryption
// */
// public DestroyableSecretKey getEncKey() {
// return new DestroyableSecretKey(getEncoded(), 0, SUBKEY_LEN_BYTES, ENC_ALG);
// }
//
// /**
// * Get the MAC subkey.
// *
// * @return A new copy of the subkey used for message authentication
// */
// public DestroyableSecretKey getMacKey() {
// return new DestroyableSecretKey(getEncoded(), SUBKEY_LEN_BYTES, SUBKEY_LEN_BYTES, MAC_ALG);
// }
//
// }
| import com.google.common.io.BaseEncoding;
import org.cryptomator.cryptolib.api.AuthenticationFailedException;
import org.cryptomator.cryptolib.api.Masterkey;
import org.cryptomator.siv.UnauthenticCiphertextException;
import org.hamcrest.CoreMatchers;
import org.hamcrest.MatcherAssert;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import java.util.UUID;
import java.util.stream.Stream;
import static java.nio.charset.StandardCharsets.UTF_8; | /*******************************************************************************
* Copyright (c) 2015, 2016 Sebastian Stenzel and others.
* This file is licensed under the terms of the MIT license.
* See the LICENSE.txt file for more info.
*
* Contributors:
* Sebastian Stenzel - initial API and implementation
*******************************************************************************/
package org.cryptomator.cryptolib.v1;
public class FileNameCryptorImplTest {
private static final BaseEncoding BASE32 = BaseEncoding.base32();
| // Path: src/main/java/org/cryptomator/cryptolib/api/AuthenticationFailedException.java
// public class AuthenticationFailedException extends CryptoException {
//
// public AuthenticationFailedException(String message) {
// super(message);
// }
//
// public AuthenticationFailedException(String message, Throwable cause) {
// super(message, cause);
// }
//
// }
//
// Path: src/main/java/org/cryptomator/cryptolib/api/Masterkey.java
// public class Masterkey extends DestroyableSecretKey {
//
// private static final String KEY_ALGORITHM = "MASTERKEY";
// public static final String ENC_ALG = "AES";
// public static final String MAC_ALG = "HmacSHA256";
// public static final int SUBKEY_LEN_BYTES = 32;
//
// public Masterkey(byte[] key) {
// super(checkKeyLength(key), KEY_ALGORITHM);
// }
//
// private static byte[] checkKeyLength(byte[] key) {
// Preconditions.checkArgument(key.length == SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES, "Invalid raw key length %s", key.length);
// return key;
// }
//
// public static Masterkey generate(SecureRandom csprng) {
// byte[] key = new byte[SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES];
// try {
// csprng.nextBytes(key);
// return new Masterkey(key);
// } finally {
// Arrays.fill(key, (byte) 0x00);
// }
// }
//
// public static Masterkey from(DestroyableSecretKey encKey, DestroyableSecretKey macKey) {
// Preconditions.checkArgument(encKey.getEncoded().length == SUBKEY_LEN_BYTES, "Invalid key length of encKey");
// Preconditions.checkArgument(macKey.getEncoded().length == SUBKEY_LEN_BYTES, "Invalid key length of macKey");
// byte[] key = new byte[SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES];
// try {
// System.arraycopy(encKey.getEncoded(), 0, key, 0, SUBKEY_LEN_BYTES);
// System.arraycopy(macKey.getEncoded(), 0, key, SUBKEY_LEN_BYTES, SUBKEY_LEN_BYTES);
// return new Masterkey(key);
// } finally {
// Arrays.fill(key, (byte) 0x00);
// }
// }
//
// @Override
// public Masterkey copy() {
// return new Masterkey(getEncoded());
// }
//
// /**
// * Get the encryption subkey.
// *
// * @return A new copy of the subkey used for encryption
// */
// public DestroyableSecretKey getEncKey() {
// return new DestroyableSecretKey(getEncoded(), 0, SUBKEY_LEN_BYTES, ENC_ALG);
// }
//
// /**
// * Get the MAC subkey.
// *
// * @return A new copy of the subkey used for message authentication
// */
// public DestroyableSecretKey getMacKey() {
// return new DestroyableSecretKey(getEncoded(), SUBKEY_LEN_BYTES, SUBKEY_LEN_BYTES, MAC_ALG);
// }
//
// }
// Path: src/test/java/org/cryptomator/cryptolib/v1/FileNameCryptorImplTest.java
import com.google.common.io.BaseEncoding;
import org.cryptomator.cryptolib.api.AuthenticationFailedException;
import org.cryptomator.cryptolib.api.Masterkey;
import org.cryptomator.siv.UnauthenticCiphertextException;
import org.hamcrest.CoreMatchers;
import org.hamcrest.MatcherAssert;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import java.util.UUID;
import java.util.stream.Stream;
import static java.nio.charset.StandardCharsets.UTF_8;
/*******************************************************************************
* Copyright (c) 2015, 2016 Sebastian Stenzel and others.
* This file is licensed under the terms of the MIT license.
* See the LICENSE.txt file for more info.
*
* Contributors:
* Sebastian Stenzel - initial API and implementation
*******************************************************************************/
package org.cryptomator.cryptolib.v1;
public class FileNameCryptorImplTest {
private static final BaseEncoding BASE32 = BaseEncoding.base32();
| private final Masterkey masterkey = new Masterkey(new byte[64]); |
cryptomator/cryptolib | src/test/java/org/cryptomator/cryptolib/v1/FileNameCryptorImplTest.java | // Path: src/main/java/org/cryptomator/cryptolib/api/AuthenticationFailedException.java
// public class AuthenticationFailedException extends CryptoException {
//
// public AuthenticationFailedException(String message) {
// super(message);
// }
//
// public AuthenticationFailedException(String message, Throwable cause) {
// super(message, cause);
// }
//
// }
//
// Path: src/main/java/org/cryptomator/cryptolib/api/Masterkey.java
// public class Masterkey extends DestroyableSecretKey {
//
// private static final String KEY_ALGORITHM = "MASTERKEY";
// public static final String ENC_ALG = "AES";
// public static final String MAC_ALG = "HmacSHA256";
// public static final int SUBKEY_LEN_BYTES = 32;
//
// public Masterkey(byte[] key) {
// super(checkKeyLength(key), KEY_ALGORITHM);
// }
//
// private static byte[] checkKeyLength(byte[] key) {
// Preconditions.checkArgument(key.length == SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES, "Invalid raw key length %s", key.length);
// return key;
// }
//
// public static Masterkey generate(SecureRandom csprng) {
// byte[] key = new byte[SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES];
// try {
// csprng.nextBytes(key);
// return new Masterkey(key);
// } finally {
// Arrays.fill(key, (byte) 0x00);
// }
// }
//
// public static Masterkey from(DestroyableSecretKey encKey, DestroyableSecretKey macKey) {
// Preconditions.checkArgument(encKey.getEncoded().length == SUBKEY_LEN_BYTES, "Invalid key length of encKey");
// Preconditions.checkArgument(macKey.getEncoded().length == SUBKEY_LEN_BYTES, "Invalid key length of macKey");
// byte[] key = new byte[SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES];
// try {
// System.arraycopy(encKey.getEncoded(), 0, key, 0, SUBKEY_LEN_BYTES);
// System.arraycopy(macKey.getEncoded(), 0, key, SUBKEY_LEN_BYTES, SUBKEY_LEN_BYTES);
// return new Masterkey(key);
// } finally {
// Arrays.fill(key, (byte) 0x00);
// }
// }
//
// @Override
// public Masterkey copy() {
// return new Masterkey(getEncoded());
// }
//
// /**
// * Get the encryption subkey.
// *
// * @return A new copy of the subkey used for encryption
// */
// public DestroyableSecretKey getEncKey() {
// return new DestroyableSecretKey(getEncoded(), 0, SUBKEY_LEN_BYTES, ENC_ALG);
// }
//
// /**
// * Get the MAC subkey.
// *
// * @return A new copy of the subkey used for message authentication
// */
// public DestroyableSecretKey getMacKey() {
// return new DestroyableSecretKey(getEncoded(), SUBKEY_LEN_BYTES, SUBKEY_LEN_BYTES, MAC_ALG);
// }
//
// }
| import com.google.common.io.BaseEncoding;
import org.cryptomator.cryptolib.api.AuthenticationFailedException;
import org.cryptomator.cryptolib.api.Masterkey;
import org.cryptomator.siv.UnauthenticCiphertextException;
import org.hamcrest.CoreMatchers;
import org.hamcrest.MatcherAssert;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import java.util.UUID;
import java.util.stream.Stream;
import static java.nio.charset.StandardCharsets.UTF_8; | /*******************************************************************************
* Copyright (c) 2015, 2016 Sebastian Stenzel and others.
* This file is licensed under the terms of the MIT license.
* See the LICENSE.txt file for more info.
*
* Contributors:
* Sebastian Stenzel - initial API and implementation
*******************************************************************************/
package org.cryptomator.cryptolib.v1;
public class FileNameCryptorImplTest {
private static final BaseEncoding BASE32 = BaseEncoding.base32();
private final Masterkey masterkey = new Masterkey(new byte[64]);
private final FileNameCryptorImpl filenameCryptor = new FileNameCryptorImpl(masterkey);
private static Stream<String> filenameGenerator() {
return Stream.generate(UUID::randomUUID).map(UUID::toString).limit(100);
}
@DisplayName("encrypt and decrypt file names")
@ParameterizedTest(name = "decrypt(encrypt({0}))")
@MethodSource("filenameGenerator") | // Path: src/main/java/org/cryptomator/cryptolib/api/AuthenticationFailedException.java
// public class AuthenticationFailedException extends CryptoException {
//
// public AuthenticationFailedException(String message) {
// super(message);
// }
//
// public AuthenticationFailedException(String message, Throwable cause) {
// super(message, cause);
// }
//
// }
//
// Path: src/main/java/org/cryptomator/cryptolib/api/Masterkey.java
// public class Masterkey extends DestroyableSecretKey {
//
// private static final String KEY_ALGORITHM = "MASTERKEY";
// public static final String ENC_ALG = "AES";
// public static final String MAC_ALG = "HmacSHA256";
// public static final int SUBKEY_LEN_BYTES = 32;
//
// public Masterkey(byte[] key) {
// super(checkKeyLength(key), KEY_ALGORITHM);
// }
//
// private static byte[] checkKeyLength(byte[] key) {
// Preconditions.checkArgument(key.length == SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES, "Invalid raw key length %s", key.length);
// return key;
// }
//
// public static Masterkey generate(SecureRandom csprng) {
// byte[] key = new byte[SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES];
// try {
// csprng.nextBytes(key);
// return new Masterkey(key);
// } finally {
// Arrays.fill(key, (byte) 0x00);
// }
// }
//
// public static Masterkey from(DestroyableSecretKey encKey, DestroyableSecretKey macKey) {
// Preconditions.checkArgument(encKey.getEncoded().length == SUBKEY_LEN_BYTES, "Invalid key length of encKey");
// Preconditions.checkArgument(macKey.getEncoded().length == SUBKEY_LEN_BYTES, "Invalid key length of macKey");
// byte[] key = new byte[SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES];
// try {
// System.arraycopy(encKey.getEncoded(), 0, key, 0, SUBKEY_LEN_BYTES);
// System.arraycopy(macKey.getEncoded(), 0, key, SUBKEY_LEN_BYTES, SUBKEY_LEN_BYTES);
// return new Masterkey(key);
// } finally {
// Arrays.fill(key, (byte) 0x00);
// }
// }
//
// @Override
// public Masterkey copy() {
// return new Masterkey(getEncoded());
// }
//
// /**
// * Get the encryption subkey.
// *
// * @return A new copy of the subkey used for encryption
// */
// public DestroyableSecretKey getEncKey() {
// return new DestroyableSecretKey(getEncoded(), 0, SUBKEY_LEN_BYTES, ENC_ALG);
// }
//
// /**
// * Get the MAC subkey.
// *
// * @return A new copy of the subkey used for message authentication
// */
// public DestroyableSecretKey getMacKey() {
// return new DestroyableSecretKey(getEncoded(), SUBKEY_LEN_BYTES, SUBKEY_LEN_BYTES, MAC_ALG);
// }
//
// }
// Path: src/test/java/org/cryptomator/cryptolib/v1/FileNameCryptorImplTest.java
import com.google.common.io.BaseEncoding;
import org.cryptomator.cryptolib.api.AuthenticationFailedException;
import org.cryptomator.cryptolib.api.Masterkey;
import org.cryptomator.siv.UnauthenticCiphertextException;
import org.hamcrest.CoreMatchers;
import org.hamcrest.MatcherAssert;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import java.util.UUID;
import java.util.stream.Stream;
import static java.nio.charset.StandardCharsets.UTF_8;
/*******************************************************************************
* Copyright (c) 2015, 2016 Sebastian Stenzel and others.
* This file is licensed under the terms of the MIT license.
* See the LICENSE.txt file for more info.
*
* Contributors:
* Sebastian Stenzel - initial API and implementation
*******************************************************************************/
package org.cryptomator.cryptolib.v1;
public class FileNameCryptorImplTest {
private static final BaseEncoding BASE32 = BaseEncoding.base32();
private final Masterkey masterkey = new Masterkey(new byte[64]);
private final FileNameCryptorImpl filenameCryptor = new FileNameCryptorImpl(masterkey);
private static Stream<String> filenameGenerator() {
return Stream.generate(UUID::randomUUID).map(UUID::toString).limit(100);
}
@DisplayName("encrypt and decrypt file names")
@ParameterizedTest(name = "decrypt(encrypt({0}))")
@MethodSource("filenameGenerator") | public void testDeterministicEncryptionOfFilenames(String origName) throws AuthenticationFailedException { |
cryptomator/cryptolib | src/test/java/org/cryptomator/cryptolib/v2/FileNameCryptorImplTest.java | // Path: src/main/java/org/cryptomator/cryptolib/api/AuthenticationFailedException.java
// public class AuthenticationFailedException extends CryptoException {
//
// public AuthenticationFailedException(String message) {
// super(message);
// }
//
// public AuthenticationFailedException(String message, Throwable cause) {
// super(message, cause);
// }
//
// }
//
// Path: src/main/java/org/cryptomator/cryptolib/api/Masterkey.java
// public class Masterkey extends DestroyableSecretKey {
//
// private static final String KEY_ALGORITHM = "MASTERKEY";
// public static final String ENC_ALG = "AES";
// public static final String MAC_ALG = "HmacSHA256";
// public static final int SUBKEY_LEN_BYTES = 32;
//
// public Masterkey(byte[] key) {
// super(checkKeyLength(key), KEY_ALGORITHM);
// }
//
// private static byte[] checkKeyLength(byte[] key) {
// Preconditions.checkArgument(key.length == SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES, "Invalid raw key length %s", key.length);
// return key;
// }
//
// public static Masterkey generate(SecureRandom csprng) {
// byte[] key = new byte[SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES];
// try {
// csprng.nextBytes(key);
// return new Masterkey(key);
// } finally {
// Arrays.fill(key, (byte) 0x00);
// }
// }
//
// public static Masterkey from(DestroyableSecretKey encKey, DestroyableSecretKey macKey) {
// Preconditions.checkArgument(encKey.getEncoded().length == SUBKEY_LEN_BYTES, "Invalid key length of encKey");
// Preconditions.checkArgument(macKey.getEncoded().length == SUBKEY_LEN_BYTES, "Invalid key length of macKey");
// byte[] key = new byte[SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES];
// try {
// System.arraycopy(encKey.getEncoded(), 0, key, 0, SUBKEY_LEN_BYTES);
// System.arraycopy(macKey.getEncoded(), 0, key, SUBKEY_LEN_BYTES, SUBKEY_LEN_BYTES);
// return new Masterkey(key);
// } finally {
// Arrays.fill(key, (byte) 0x00);
// }
// }
//
// @Override
// public Masterkey copy() {
// return new Masterkey(getEncoded());
// }
//
// /**
// * Get the encryption subkey.
// *
// * @return A new copy of the subkey used for encryption
// */
// public DestroyableSecretKey getEncKey() {
// return new DestroyableSecretKey(getEncoded(), 0, SUBKEY_LEN_BYTES, ENC_ALG);
// }
//
// /**
// * Get the MAC subkey.
// *
// * @return A new copy of the subkey used for message authentication
// */
// public DestroyableSecretKey getMacKey() {
// return new DestroyableSecretKey(getEncoded(), SUBKEY_LEN_BYTES, SUBKEY_LEN_BYTES, MAC_ALG);
// }
//
// }
| import com.google.common.io.BaseEncoding;
import org.cryptomator.cryptolib.api.AuthenticationFailedException;
import org.cryptomator.cryptolib.api.Masterkey;
import org.cryptomator.siv.UnauthenticCiphertextException;
import org.hamcrest.CoreMatchers;
import org.hamcrest.MatcherAssert;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import java.util.UUID;
import java.util.stream.Stream;
import static java.nio.charset.StandardCharsets.UTF_8; | /*******************************************************************************
* Copyright (c) 2015, 2016 Sebastian Stenzel and others.
* This file is licensed under the terms of the MIT license.
* See the LICENSE.txt file for more info.
*
* Contributors:
* Sebastian Stenzel - initial API and implementation
*******************************************************************************/
package org.cryptomator.cryptolib.v2;
public class FileNameCryptorImplTest {
private static final BaseEncoding BASE32 = BaseEncoding.base32();
| // Path: src/main/java/org/cryptomator/cryptolib/api/AuthenticationFailedException.java
// public class AuthenticationFailedException extends CryptoException {
//
// public AuthenticationFailedException(String message) {
// super(message);
// }
//
// public AuthenticationFailedException(String message, Throwable cause) {
// super(message, cause);
// }
//
// }
//
// Path: src/main/java/org/cryptomator/cryptolib/api/Masterkey.java
// public class Masterkey extends DestroyableSecretKey {
//
// private static final String KEY_ALGORITHM = "MASTERKEY";
// public static final String ENC_ALG = "AES";
// public static final String MAC_ALG = "HmacSHA256";
// public static final int SUBKEY_LEN_BYTES = 32;
//
// public Masterkey(byte[] key) {
// super(checkKeyLength(key), KEY_ALGORITHM);
// }
//
// private static byte[] checkKeyLength(byte[] key) {
// Preconditions.checkArgument(key.length == SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES, "Invalid raw key length %s", key.length);
// return key;
// }
//
// public static Masterkey generate(SecureRandom csprng) {
// byte[] key = new byte[SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES];
// try {
// csprng.nextBytes(key);
// return new Masterkey(key);
// } finally {
// Arrays.fill(key, (byte) 0x00);
// }
// }
//
// public static Masterkey from(DestroyableSecretKey encKey, DestroyableSecretKey macKey) {
// Preconditions.checkArgument(encKey.getEncoded().length == SUBKEY_LEN_BYTES, "Invalid key length of encKey");
// Preconditions.checkArgument(macKey.getEncoded().length == SUBKEY_LEN_BYTES, "Invalid key length of macKey");
// byte[] key = new byte[SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES];
// try {
// System.arraycopy(encKey.getEncoded(), 0, key, 0, SUBKEY_LEN_BYTES);
// System.arraycopy(macKey.getEncoded(), 0, key, SUBKEY_LEN_BYTES, SUBKEY_LEN_BYTES);
// return new Masterkey(key);
// } finally {
// Arrays.fill(key, (byte) 0x00);
// }
// }
//
// @Override
// public Masterkey copy() {
// return new Masterkey(getEncoded());
// }
//
// /**
// * Get the encryption subkey.
// *
// * @return A new copy of the subkey used for encryption
// */
// public DestroyableSecretKey getEncKey() {
// return new DestroyableSecretKey(getEncoded(), 0, SUBKEY_LEN_BYTES, ENC_ALG);
// }
//
// /**
// * Get the MAC subkey.
// *
// * @return A new copy of the subkey used for message authentication
// */
// public DestroyableSecretKey getMacKey() {
// return new DestroyableSecretKey(getEncoded(), SUBKEY_LEN_BYTES, SUBKEY_LEN_BYTES, MAC_ALG);
// }
//
// }
// Path: src/test/java/org/cryptomator/cryptolib/v2/FileNameCryptorImplTest.java
import com.google.common.io.BaseEncoding;
import org.cryptomator.cryptolib.api.AuthenticationFailedException;
import org.cryptomator.cryptolib.api.Masterkey;
import org.cryptomator.siv.UnauthenticCiphertextException;
import org.hamcrest.CoreMatchers;
import org.hamcrest.MatcherAssert;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import java.util.UUID;
import java.util.stream.Stream;
import static java.nio.charset.StandardCharsets.UTF_8;
/*******************************************************************************
* Copyright (c) 2015, 2016 Sebastian Stenzel and others.
* This file is licensed under the terms of the MIT license.
* See the LICENSE.txt file for more info.
*
* Contributors:
* Sebastian Stenzel - initial API and implementation
*******************************************************************************/
package org.cryptomator.cryptolib.v2;
public class FileNameCryptorImplTest {
private static final BaseEncoding BASE32 = BaseEncoding.base32();
| private final Masterkey masterkey = new Masterkey(new byte[64]); |
cryptomator/cryptolib | src/test/java/org/cryptomator/cryptolib/v2/FileNameCryptorImplTest.java | // Path: src/main/java/org/cryptomator/cryptolib/api/AuthenticationFailedException.java
// public class AuthenticationFailedException extends CryptoException {
//
// public AuthenticationFailedException(String message) {
// super(message);
// }
//
// public AuthenticationFailedException(String message, Throwable cause) {
// super(message, cause);
// }
//
// }
//
// Path: src/main/java/org/cryptomator/cryptolib/api/Masterkey.java
// public class Masterkey extends DestroyableSecretKey {
//
// private static final String KEY_ALGORITHM = "MASTERKEY";
// public static final String ENC_ALG = "AES";
// public static final String MAC_ALG = "HmacSHA256";
// public static final int SUBKEY_LEN_BYTES = 32;
//
// public Masterkey(byte[] key) {
// super(checkKeyLength(key), KEY_ALGORITHM);
// }
//
// private static byte[] checkKeyLength(byte[] key) {
// Preconditions.checkArgument(key.length == SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES, "Invalid raw key length %s", key.length);
// return key;
// }
//
// public static Masterkey generate(SecureRandom csprng) {
// byte[] key = new byte[SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES];
// try {
// csprng.nextBytes(key);
// return new Masterkey(key);
// } finally {
// Arrays.fill(key, (byte) 0x00);
// }
// }
//
// public static Masterkey from(DestroyableSecretKey encKey, DestroyableSecretKey macKey) {
// Preconditions.checkArgument(encKey.getEncoded().length == SUBKEY_LEN_BYTES, "Invalid key length of encKey");
// Preconditions.checkArgument(macKey.getEncoded().length == SUBKEY_LEN_BYTES, "Invalid key length of macKey");
// byte[] key = new byte[SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES];
// try {
// System.arraycopy(encKey.getEncoded(), 0, key, 0, SUBKEY_LEN_BYTES);
// System.arraycopy(macKey.getEncoded(), 0, key, SUBKEY_LEN_BYTES, SUBKEY_LEN_BYTES);
// return new Masterkey(key);
// } finally {
// Arrays.fill(key, (byte) 0x00);
// }
// }
//
// @Override
// public Masterkey copy() {
// return new Masterkey(getEncoded());
// }
//
// /**
// * Get the encryption subkey.
// *
// * @return A new copy of the subkey used for encryption
// */
// public DestroyableSecretKey getEncKey() {
// return new DestroyableSecretKey(getEncoded(), 0, SUBKEY_LEN_BYTES, ENC_ALG);
// }
//
// /**
// * Get the MAC subkey.
// *
// * @return A new copy of the subkey used for message authentication
// */
// public DestroyableSecretKey getMacKey() {
// return new DestroyableSecretKey(getEncoded(), SUBKEY_LEN_BYTES, SUBKEY_LEN_BYTES, MAC_ALG);
// }
//
// }
| import com.google.common.io.BaseEncoding;
import org.cryptomator.cryptolib.api.AuthenticationFailedException;
import org.cryptomator.cryptolib.api.Masterkey;
import org.cryptomator.siv.UnauthenticCiphertextException;
import org.hamcrest.CoreMatchers;
import org.hamcrest.MatcherAssert;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import java.util.UUID;
import java.util.stream.Stream;
import static java.nio.charset.StandardCharsets.UTF_8; | /*******************************************************************************
* Copyright (c) 2015, 2016 Sebastian Stenzel and others.
* This file is licensed under the terms of the MIT license.
* See the LICENSE.txt file for more info.
*
* Contributors:
* Sebastian Stenzel - initial API and implementation
*******************************************************************************/
package org.cryptomator.cryptolib.v2;
public class FileNameCryptorImplTest {
private static final BaseEncoding BASE32 = BaseEncoding.base32();
private final Masterkey masterkey = new Masterkey(new byte[64]);
private final FileNameCryptorImpl filenameCryptor = new FileNameCryptorImpl(masterkey);
private static Stream<String> filenameGenerator() {
return Stream.generate(UUID::randomUUID).map(UUID::toString).limit(100);
}
@DisplayName("encrypt and decrypt file names")
@ParameterizedTest(name = "decrypt(encrypt({0}))")
@MethodSource("filenameGenerator") | // Path: src/main/java/org/cryptomator/cryptolib/api/AuthenticationFailedException.java
// public class AuthenticationFailedException extends CryptoException {
//
// public AuthenticationFailedException(String message) {
// super(message);
// }
//
// public AuthenticationFailedException(String message, Throwable cause) {
// super(message, cause);
// }
//
// }
//
// Path: src/main/java/org/cryptomator/cryptolib/api/Masterkey.java
// public class Masterkey extends DestroyableSecretKey {
//
// private static final String KEY_ALGORITHM = "MASTERKEY";
// public static final String ENC_ALG = "AES";
// public static final String MAC_ALG = "HmacSHA256";
// public static final int SUBKEY_LEN_BYTES = 32;
//
// public Masterkey(byte[] key) {
// super(checkKeyLength(key), KEY_ALGORITHM);
// }
//
// private static byte[] checkKeyLength(byte[] key) {
// Preconditions.checkArgument(key.length == SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES, "Invalid raw key length %s", key.length);
// return key;
// }
//
// public static Masterkey generate(SecureRandom csprng) {
// byte[] key = new byte[SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES];
// try {
// csprng.nextBytes(key);
// return new Masterkey(key);
// } finally {
// Arrays.fill(key, (byte) 0x00);
// }
// }
//
// public static Masterkey from(DestroyableSecretKey encKey, DestroyableSecretKey macKey) {
// Preconditions.checkArgument(encKey.getEncoded().length == SUBKEY_LEN_BYTES, "Invalid key length of encKey");
// Preconditions.checkArgument(macKey.getEncoded().length == SUBKEY_LEN_BYTES, "Invalid key length of macKey");
// byte[] key = new byte[SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES];
// try {
// System.arraycopy(encKey.getEncoded(), 0, key, 0, SUBKEY_LEN_BYTES);
// System.arraycopy(macKey.getEncoded(), 0, key, SUBKEY_LEN_BYTES, SUBKEY_LEN_BYTES);
// return new Masterkey(key);
// } finally {
// Arrays.fill(key, (byte) 0x00);
// }
// }
//
// @Override
// public Masterkey copy() {
// return new Masterkey(getEncoded());
// }
//
// /**
// * Get the encryption subkey.
// *
// * @return A new copy of the subkey used for encryption
// */
// public DestroyableSecretKey getEncKey() {
// return new DestroyableSecretKey(getEncoded(), 0, SUBKEY_LEN_BYTES, ENC_ALG);
// }
//
// /**
// * Get the MAC subkey.
// *
// * @return A new copy of the subkey used for message authentication
// */
// public DestroyableSecretKey getMacKey() {
// return new DestroyableSecretKey(getEncoded(), SUBKEY_LEN_BYTES, SUBKEY_LEN_BYTES, MAC_ALG);
// }
//
// }
// Path: src/test/java/org/cryptomator/cryptolib/v2/FileNameCryptorImplTest.java
import com.google.common.io.BaseEncoding;
import org.cryptomator.cryptolib.api.AuthenticationFailedException;
import org.cryptomator.cryptolib.api.Masterkey;
import org.cryptomator.siv.UnauthenticCiphertextException;
import org.hamcrest.CoreMatchers;
import org.hamcrest.MatcherAssert;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import java.util.UUID;
import java.util.stream.Stream;
import static java.nio.charset.StandardCharsets.UTF_8;
/*******************************************************************************
* Copyright (c) 2015, 2016 Sebastian Stenzel and others.
* This file is licensed under the terms of the MIT license.
* See the LICENSE.txt file for more info.
*
* Contributors:
* Sebastian Stenzel - initial API and implementation
*******************************************************************************/
package org.cryptomator.cryptolib.v2;
public class FileNameCryptorImplTest {
private static final BaseEncoding BASE32 = BaseEncoding.base32();
private final Masterkey masterkey = new Masterkey(new byte[64]);
private final FileNameCryptorImpl filenameCryptor = new FileNameCryptorImpl(masterkey);
private static Stream<String> filenameGenerator() {
return Stream.generate(UUID::randomUUID).map(UUID::toString).limit(100);
}
@DisplayName("encrypt and decrypt file names")
@ParameterizedTest(name = "decrypt(encrypt({0}))")
@MethodSource("filenameGenerator") | public void testDeterministicEncryptionOfFilenames(String origName) throws AuthenticationFailedException { |
cryptomator/cryptolib | src/main/java/org/cryptomator/cryptolib/common/EncryptingWritableByteChannel.java | // Path: src/main/java/org/cryptomator/cryptolib/api/Cryptor.java
// public interface Cryptor extends Destroyable, AutoCloseable {
//
// FileContentCryptor fileContentCryptor();
//
// FileHeaderCryptor fileHeaderCryptor();
//
// FileNameCryptor fileNameCryptor();
//
// @Override
// void destroy();
//
// /**
// * Calls {@link #destroy()}.
// */
// @Override
// default void close() {
// destroy();
// }
//
// }
//
// Path: src/main/java/org/cryptomator/cryptolib/api/FileHeader.java
// public interface FileHeader {
//
// /**
// * Returns the value of a currently unused 64 bit field in the file header.
// * <p>
// * Formerly used for storing the plaintext file size.
// *
// * @return 64 bit integer for future use.
// * @deprecated Don't rely on this method. It may be redefined any time.
// */
// @Deprecated
// long getReserved();
//
// /**
// * Sets the 64 bit field in the file header.
// * <p>
// * Formerly used for storing the plaintext file size.
// *
// * @param reserved 64 bit integer for future use
// * @deprecated Don't rely on this method. It may be redefined any time.
// */
// @Deprecated
// void setReserved(long reserved);
//
// }
| import org.cryptomator.cryptolib.api.Cryptor;
import org.cryptomator.cryptolib.api.FileHeader;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.WritableByteChannel; | /*******************************************************************************
* Copyright (c) 2016 Sebastian Stenzel and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the accompanying LICENSE.txt.
*
* Contributors:
* Sebastian Stenzel - initial API and implementation
*******************************************************************************/
package org.cryptomator.cryptolib.common;
public class EncryptingWritableByteChannel implements WritableByteChannel {
private final WritableByteChannel delegate; | // Path: src/main/java/org/cryptomator/cryptolib/api/Cryptor.java
// public interface Cryptor extends Destroyable, AutoCloseable {
//
// FileContentCryptor fileContentCryptor();
//
// FileHeaderCryptor fileHeaderCryptor();
//
// FileNameCryptor fileNameCryptor();
//
// @Override
// void destroy();
//
// /**
// * Calls {@link #destroy()}.
// */
// @Override
// default void close() {
// destroy();
// }
//
// }
//
// Path: src/main/java/org/cryptomator/cryptolib/api/FileHeader.java
// public interface FileHeader {
//
// /**
// * Returns the value of a currently unused 64 bit field in the file header.
// * <p>
// * Formerly used for storing the plaintext file size.
// *
// * @return 64 bit integer for future use.
// * @deprecated Don't rely on this method. It may be redefined any time.
// */
// @Deprecated
// long getReserved();
//
// /**
// * Sets the 64 bit field in the file header.
// * <p>
// * Formerly used for storing the plaintext file size.
// *
// * @param reserved 64 bit integer for future use
// * @deprecated Don't rely on this method. It may be redefined any time.
// */
// @Deprecated
// void setReserved(long reserved);
//
// }
// Path: src/main/java/org/cryptomator/cryptolib/common/EncryptingWritableByteChannel.java
import org.cryptomator.cryptolib.api.Cryptor;
import org.cryptomator.cryptolib.api.FileHeader;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.WritableByteChannel;
/*******************************************************************************
* Copyright (c) 2016 Sebastian Stenzel and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the accompanying LICENSE.txt.
*
* Contributors:
* Sebastian Stenzel - initial API and implementation
*******************************************************************************/
package org.cryptomator.cryptolib.common;
public class EncryptingWritableByteChannel implements WritableByteChannel {
private final WritableByteChannel delegate; | private final Cryptor cryptor; |
cryptomator/cryptolib | src/main/java/org/cryptomator/cryptolib/common/EncryptingWritableByteChannel.java | // Path: src/main/java/org/cryptomator/cryptolib/api/Cryptor.java
// public interface Cryptor extends Destroyable, AutoCloseable {
//
// FileContentCryptor fileContentCryptor();
//
// FileHeaderCryptor fileHeaderCryptor();
//
// FileNameCryptor fileNameCryptor();
//
// @Override
// void destroy();
//
// /**
// * Calls {@link #destroy()}.
// */
// @Override
// default void close() {
// destroy();
// }
//
// }
//
// Path: src/main/java/org/cryptomator/cryptolib/api/FileHeader.java
// public interface FileHeader {
//
// /**
// * Returns the value of a currently unused 64 bit field in the file header.
// * <p>
// * Formerly used for storing the plaintext file size.
// *
// * @return 64 bit integer for future use.
// * @deprecated Don't rely on this method. It may be redefined any time.
// */
// @Deprecated
// long getReserved();
//
// /**
// * Sets the 64 bit field in the file header.
// * <p>
// * Formerly used for storing the plaintext file size.
// *
// * @param reserved 64 bit integer for future use
// * @deprecated Don't rely on this method. It may be redefined any time.
// */
// @Deprecated
// void setReserved(long reserved);
//
// }
| import org.cryptomator.cryptolib.api.Cryptor;
import org.cryptomator.cryptolib.api.FileHeader;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.WritableByteChannel; | /*******************************************************************************
* Copyright (c) 2016 Sebastian Stenzel and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the accompanying LICENSE.txt.
*
* Contributors:
* Sebastian Stenzel - initial API and implementation
*******************************************************************************/
package org.cryptomator.cryptolib.common;
public class EncryptingWritableByteChannel implements WritableByteChannel {
private final WritableByteChannel delegate;
private final Cryptor cryptor; | // Path: src/main/java/org/cryptomator/cryptolib/api/Cryptor.java
// public interface Cryptor extends Destroyable, AutoCloseable {
//
// FileContentCryptor fileContentCryptor();
//
// FileHeaderCryptor fileHeaderCryptor();
//
// FileNameCryptor fileNameCryptor();
//
// @Override
// void destroy();
//
// /**
// * Calls {@link #destroy()}.
// */
// @Override
// default void close() {
// destroy();
// }
//
// }
//
// Path: src/main/java/org/cryptomator/cryptolib/api/FileHeader.java
// public interface FileHeader {
//
// /**
// * Returns the value of a currently unused 64 bit field in the file header.
// * <p>
// * Formerly used for storing the plaintext file size.
// *
// * @return 64 bit integer for future use.
// * @deprecated Don't rely on this method. It may be redefined any time.
// */
// @Deprecated
// long getReserved();
//
// /**
// * Sets the 64 bit field in the file header.
// * <p>
// * Formerly used for storing the plaintext file size.
// *
// * @param reserved 64 bit integer for future use
// * @deprecated Don't rely on this method. It may be redefined any time.
// */
// @Deprecated
// void setReserved(long reserved);
//
// }
// Path: src/main/java/org/cryptomator/cryptolib/common/EncryptingWritableByteChannel.java
import org.cryptomator.cryptolib.api.Cryptor;
import org.cryptomator.cryptolib.api.FileHeader;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.WritableByteChannel;
/*******************************************************************************
* Copyright (c) 2016 Sebastian Stenzel and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the accompanying LICENSE.txt.
*
* Contributors:
* Sebastian Stenzel - initial API and implementation
*******************************************************************************/
package org.cryptomator.cryptolib.common;
public class EncryptingWritableByteChannel implements WritableByteChannel {
private final WritableByteChannel delegate;
private final Cryptor cryptor; | private final FileHeader header; |
cryptomator/cryptolib | src/main/java/org/cryptomator/cryptolib/common/MasterkeyFileAccess.java | // Path: src/main/java/org/cryptomator/cryptolib/api/InvalidPassphraseException.java
// public class InvalidPassphraseException extends MasterkeyLoadingFailedException {
//
// public InvalidPassphraseException() {
// super(null);
// }
// }
//
// Path: src/main/java/org/cryptomator/cryptolib/api/Masterkey.java
// public class Masterkey extends DestroyableSecretKey {
//
// private static final String KEY_ALGORITHM = "MASTERKEY";
// public static final String ENC_ALG = "AES";
// public static final String MAC_ALG = "HmacSHA256";
// public static final int SUBKEY_LEN_BYTES = 32;
//
// public Masterkey(byte[] key) {
// super(checkKeyLength(key), KEY_ALGORITHM);
// }
//
// private static byte[] checkKeyLength(byte[] key) {
// Preconditions.checkArgument(key.length == SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES, "Invalid raw key length %s", key.length);
// return key;
// }
//
// public static Masterkey generate(SecureRandom csprng) {
// byte[] key = new byte[SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES];
// try {
// csprng.nextBytes(key);
// return new Masterkey(key);
// } finally {
// Arrays.fill(key, (byte) 0x00);
// }
// }
//
// public static Masterkey from(DestroyableSecretKey encKey, DestroyableSecretKey macKey) {
// Preconditions.checkArgument(encKey.getEncoded().length == SUBKEY_LEN_BYTES, "Invalid key length of encKey");
// Preconditions.checkArgument(macKey.getEncoded().length == SUBKEY_LEN_BYTES, "Invalid key length of macKey");
// byte[] key = new byte[SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES];
// try {
// System.arraycopy(encKey.getEncoded(), 0, key, 0, SUBKEY_LEN_BYTES);
// System.arraycopy(macKey.getEncoded(), 0, key, SUBKEY_LEN_BYTES, SUBKEY_LEN_BYTES);
// return new Masterkey(key);
// } finally {
// Arrays.fill(key, (byte) 0x00);
// }
// }
//
// @Override
// public Masterkey copy() {
// return new Masterkey(getEncoded());
// }
//
// /**
// * Get the encryption subkey.
// *
// * @return A new copy of the subkey used for encryption
// */
// public DestroyableSecretKey getEncKey() {
// return new DestroyableSecretKey(getEncoded(), 0, SUBKEY_LEN_BYTES, ENC_ALG);
// }
//
// /**
// * Get the MAC subkey.
// *
// * @return A new copy of the subkey used for message authentication
// */
// public DestroyableSecretKey getMacKey() {
// return new DestroyableSecretKey(getEncoded(), SUBKEY_LEN_BYTES, SUBKEY_LEN_BYTES, MAC_ALG);
// }
//
// }
//
// Path: src/main/java/org/cryptomator/cryptolib/api/MasterkeyLoadingFailedException.java
// public class MasterkeyLoadingFailedException extends CryptoException {
//
// public MasterkeyLoadingFailedException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public MasterkeyLoadingFailedException(String message) {
// super(message);
// }
//
// }
| import com.google.common.base.Preconditions;
import org.cryptomator.cryptolib.api.InvalidPassphraseException;
import org.cryptomator.cryptolib.api.Masterkey;
import org.cryptomator.cryptolib.api.MasterkeyLoadingFailedException;
import javax.crypto.Mac;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.Writer;
import java.nio.ByteBuffer;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.nio.file.StandardOpenOption;
import java.security.InvalidKeyException;
import java.security.SecureRandom;
import java.util.Arrays;
import static java.nio.charset.StandardCharsets.UTF_8; |
/**
* Reencrypts a masterkey with a new passphrase.
*
* @param masterkey The original JSON representation of the masterkey
* @param oldPassphrase The old passphrase
* @param newPassphrase The new passphrase
* @return A JSON representation of the masterkey, now encrypted with <code>newPassphrase</code>
* @throws IOException If failing to read, parse or write JSON
* @throws InvalidPassphraseException If the wrong <code>oldPassphrase</code> has been supplied for the <code>masterkey</code>
*/
public byte[] changePassphrase(byte[] masterkey, CharSequence oldPassphrase, CharSequence newPassphrase) throws IOException, InvalidPassphraseException {
try (ByteArrayInputStream in = new ByteArrayInputStream(masterkey);
ByteArrayOutputStream out = new ByteArrayOutputStream()) {
changePassphrase(in, out, oldPassphrase, newPassphrase);
return out.toByteArray();
}
}
public void changePassphrase(InputStream oldIn, OutputStream newOut, CharSequence oldPassphrase, CharSequence newPassphrase) throws IOException, InvalidPassphraseException {
try (Reader reader = new InputStreamReader(oldIn, UTF_8);
Writer writer = new OutputStreamWriter(newOut, UTF_8)) {
MasterkeyFile original = MasterkeyFile.read(reader);
MasterkeyFile updated = changePassphrase(original, oldPassphrase, newPassphrase);
updated.write(writer);
}
}
// visible for testing
MasterkeyFile changePassphrase(MasterkeyFile masterkey, CharSequence oldPassphrase, CharSequence newPassphrase) throws InvalidPassphraseException { | // Path: src/main/java/org/cryptomator/cryptolib/api/InvalidPassphraseException.java
// public class InvalidPassphraseException extends MasterkeyLoadingFailedException {
//
// public InvalidPassphraseException() {
// super(null);
// }
// }
//
// Path: src/main/java/org/cryptomator/cryptolib/api/Masterkey.java
// public class Masterkey extends DestroyableSecretKey {
//
// private static final String KEY_ALGORITHM = "MASTERKEY";
// public static final String ENC_ALG = "AES";
// public static final String MAC_ALG = "HmacSHA256";
// public static final int SUBKEY_LEN_BYTES = 32;
//
// public Masterkey(byte[] key) {
// super(checkKeyLength(key), KEY_ALGORITHM);
// }
//
// private static byte[] checkKeyLength(byte[] key) {
// Preconditions.checkArgument(key.length == SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES, "Invalid raw key length %s", key.length);
// return key;
// }
//
// public static Masterkey generate(SecureRandom csprng) {
// byte[] key = new byte[SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES];
// try {
// csprng.nextBytes(key);
// return new Masterkey(key);
// } finally {
// Arrays.fill(key, (byte) 0x00);
// }
// }
//
// public static Masterkey from(DestroyableSecretKey encKey, DestroyableSecretKey macKey) {
// Preconditions.checkArgument(encKey.getEncoded().length == SUBKEY_LEN_BYTES, "Invalid key length of encKey");
// Preconditions.checkArgument(macKey.getEncoded().length == SUBKEY_LEN_BYTES, "Invalid key length of macKey");
// byte[] key = new byte[SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES];
// try {
// System.arraycopy(encKey.getEncoded(), 0, key, 0, SUBKEY_LEN_BYTES);
// System.arraycopy(macKey.getEncoded(), 0, key, SUBKEY_LEN_BYTES, SUBKEY_LEN_BYTES);
// return new Masterkey(key);
// } finally {
// Arrays.fill(key, (byte) 0x00);
// }
// }
//
// @Override
// public Masterkey copy() {
// return new Masterkey(getEncoded());
// }
//
// /**
// * Get the encryption subkey.
// *
// * @return A new copy of the subkey used for encryption
// */
// public DestroyableSecretKey getEncKey() {
// return new DestroyableSecretKey(getEncoded(), 0, SUBKEY_LEN_BYTES, ENC_ALG);
// }
//
// /**
// * Get the MAC subkey.
// *
// * @return A new copy of the subkey used for message authentication
// */
// public DestroyableSecretKey getMacKey() {
// return new DestroyableSecretKey(getEncoded(), SUBKEY_LEN_BYTES, SUBKEY_LEN_BYTES, MAC_ALG);
// }
//
// }
//
// Path: src/main/java/org/cryptomator/cryptolib/api/MasterkeyLoadingFailedException.java
// public class MasterkeyLoadingFailedException extends CryptoException {
//
// public MasterkeyLoadingFailedException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public MasterkeyLoadingFailedException(String message) {
// super(message);
// }
//
// }
// Path: src/main/java/org/cryptomator/cryptolib/common/MasterkeyFileAccess.java
import com.google.common.base.Preconditions;
import org.cryptomator.cryptolib.api.InvalidPassphraseException;
import org.cryptomator.cryptolib.api.Masterkey;
import org.cryptomator.cryptolib.api.MasterkeyLoadingFailedException;
import javax.crypto.Mac;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.Writer;
import java.nio.ByteBuffer;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.nio.file.StandardOpenOption;
import java.security.InvalidKeyException;
import java.security.SecureRandom;
import java.util.Arrays;
import static java.nio.charset.StandardCharsets.UTF_8;
/**
* Reencrypts a masterkey with a new passphrase.
*
* @param masterkey The original JSON representation of the masterkey
* @param oldPassphrase The old passphrase
* @param newPassphrase The new passphrase
* @return A JSON representation of the masterkey, now encrypted with <code>newPassphrase</code>
* @throws IOException If failing to read, parse or write JSON
* @throws InvalidPassphraseException If the wrong <code>oldPassphrase</code> has been supplied for the <code>masterkey</code>
*/
public byte[] changePassphrase(byte[] masterkey, CharSequence oldPassphrase, CharSequence newPassphrase) throws IOException, InvalidPassphraseException {
try (ByteArrayInputStream in = new ByteArrayInputStream(masterkey);
ByteArrayOutputStream out = new ByteArrayOutputStream()) {
changePassphrase(in, out, oldPassphrase, newPassphrase);
return out.toByteArray();
}
}
public void changePassphrase(InputStream oldIn, OutputStream newOut, CharSequence oldPassphrase, CharSequence newPassphrase) throws IOException, InvalidPassphraseException {
try (Reader reader = new InputStreamReader(oldIn, UTF_8);
Writer writer = new OutputStreamWriter(newOut, UTF_8)) {
MasterkeyFile original = MasterkeyFile.read(reader);
MasterkeyFile updated = changePassphrase(original, oldPassphrase, newPassphrase);
updated.write(writer);
}
}
// visible for testing
MasterkeyFile changePassphrase(MasterkeyFile masterkey, CharSequence oldPassphrase, CharSequence newPassphrase) throws InvalidPassphraseException { | try (Masterkey key = unlock(masterkey, oldPassphrase)) { |
cryptomator/cryptolib | src/main/java/org/cryptomator/cryptolib/common/MasterkeyFileAccess.java | // Path: src/main/java/org/cryptomator/cryptolib/api/InvalidPassphraseException.java
// public class InvalidPassphraseException extends MasterkeyLoadingFailedException {
//
// public InvalidPassphraseException() {
// super(null);
// }
// }
//
// Path: src/main/java/org/cryptomator/cryptolib/api/Masterkey.java
// public class Masterkey extends DestroyableSecretKey {
//
// private static final String KEY_ALGORITHM = "MASTERKEY";
// public static final String ENC_ALG = "AES";
// public static final String MAC_ALG = "HmacSHA256";
// public static final int SUBKEY_LEN_BYTES = 32;
//
// public Masterkey(byte[] key) {
// super(checkKeyLength(key), KEY_ALGORITHM);
// }
//
// private static byte[] checkKeyLength(byte[] key) {
// Preconditions.checkArgument(key.length == SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES, "Invalid raw key length %s", key.length);
// return key;
// }
//
// public static Masterkey generate(SecureRandom csprng) {
// byte[] key = new byte[SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES];
// try {
// csprng.nextBytes(key);
// return new Masterkey(key);
// } finally {
// Arrays.fill(key, (byte) 0x00);
// }
// }
//
// public static Masterkey from(DestroyableSecretKey encKey, DestroyableSecretKey macKey) {
// Preconditions.checkArgument(encKey.getEncoded().length == SUBKEY_LEN_BYTES, "Invalid key length of encKey");
// Preconditions.checkArgument(macKey.getEncoded().length == SUBKEY_LEN_BYTES, "Invalid key length of macKey");
// byte[] key = new byte[SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES];
// try {
// System.arraycopy(encKey.getEncoded(), 0, key, 0, SUBKEY_LEN_BYTES);
// System.arraycopy(macKey.getEncoded(), 0, key, SUBKEY_LEN_BYTES, SUBKEY_LEN_BYTES);
// return new Masterkey(key);
// } finally {
// Arrays.fill(key, (byte) 0x00);
// }
// }
//
// @Override
// public Masterkey copy() {
// return new Masterkey(getEncoded());
// }
//
// /**
// * Get the encryption subkey.
// *
// * @return A new copy of the subkey used for encryption
// */
// public DestroyableSecretKey getEncKey() {
// return new DestroyableSecretKey(getEncoded(), 0, SUBKEY_LEN_BYTES, ENC_ALG);
// }
//
// /**
// * Get the MAC subkey.
// *
// * @return A new copy of the subkey used for message authentication
// */
// public DestroyableSecretKey getMacKey() {
// return new DestroyableSecretKey(getEncoded(), SUBKEY_LEN_BYTES, SUBKEY_LEN_BYTES, MAC_ALG);
// }
//
// }
//
// Path: src/main/java/org/cryptomator/cryptolib/api/MasterkeyLoadingFailedException.java
// public class MasterkeyLoadingFailedException extends CryptoException {
//
// public MasterkeyLoadingFailedException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public MasterkeyLoadingFailedException(String message) {
// super(message);
// }
//
// }
| import com.google.common.base.Preconditions;
import org.cryptomator.cryptolib.api.InvalidPassphraseException;
import org.cryptomator.cryptolib.api.Masterkey;
import org.cryptomator.cryptolib.api.MasterkeyLoadingFailedException;
import javax.crypto.Mac;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.Writer;
import java.nio.ByteBuffer;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.nio.file.StandardOpenOption;
import java.security.InvalidKeyException;
import java.security.SecureRandom;
import java.util.Arrays;
import static java.nio.charset.StandardCharsets.UTF_8; | return out.toByteArray();
}
}
public void changePassphrase(InputStream oldIn, OutputStream newOut, CharSequence oldPassphrase, CharSequence newPassphrase) throws IOException, InvalidPassphraseException {
try (Reader reader = new InputStreamReader(oldIn, UTF_8);
Writer writer = new OutputStreamWriter(newOut, UTF_8)) {
MasterkeyFile original = MasterkeyFile.read(reader);
MasterkeyFile updated = changePassphrase(original, oldPassphrase, newPassphrase);
updated.write(writer);
}
}
// visible for testing
MasterkeyFile changePassphrase(MasterkeyFile masterkey, CharSequence oldPassphrase, CharSequence newPassphrase) throws InvalidPassphraseException {
try (Masterkey key = unlock(masterkey, oldPassphrase)) {
return lock(key, newPassphrase, masterkey.version, masterkey.scryptCostParam);
}
}
/**
* Loads the JSON contents from the given file and derives a KEK from the given passphrase to
* unwrap the contained keys.
*
* @param filePath Which file to load
* @param passphrase The passphrase used during key derivation
* @return A new masterkey. Should be used in a try-with-resource statement.
* @throws InvalidPassphraseException If the provided passphrase can not be used to unwrap the stored keys.
* @throws MasterkeyLoadingFailedException If reading the masterkey file fails
*/ | // Path: src/main/java/org/cryptomator/cryptolib/api/InvalidPassphraseException.java
// public class InvalidPassphraseException extends MasterkeyLoadingFailedException {
//
// public InvalidPassphraseException() {
// super(null);
// }
// }
//
// Path: src/main/java/org/cryptomator/cryptolib/api/Masterkey.java
// public class Masterkey extends DestroyableSecretKey {
//
// private static final String KEY_ALGORITHM = "MASTERKEY";
// public static final String ENC_ALG = "AES";
// public static final String MAC_ALG = "HmacSHA256";
// public static final int SUBKEY_LEN_BYTES = 32;
//
// public Masterkey(byte[] key) {
// super(checkKeyLength(key), KEY_ALGORITHM);
// }
//
// private static byte[] checkKeyLength(byte[] key) {
// Preconditions.checkArgument(key.length == SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES, "Invalid raw key length %s", key.length);
// return key;
// }
//
// public static Masterkey generate(SecureRandom csprng) {
// byte[] key = new byte[SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES];
// try {
// csprng.nextBytes(key);
// return new Masterkey(key);
// } finally {
// Arrays.fill(key, (byte) 0x00);
// }
// }
//
// public static Masterkey from(DestroyableSecretKey encKey, DestroyableSecretKey macKey) {
// Preconditions.checkArgument(encKey.getEncoded().length == SUBKEY_LEN_BYTES, "Invalid key length of encKey");
// Preconditions.checkArgument(macKey.getEncoded().length == SUBKEY_LEN_BYTES, "Invalid key length of macKey");
// byte[] key = new byte[SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES];
// try {
// System.arraycopy(encKey.getEncoded(), 0, key, 0, SUBKEY_LEN_BYTES);
// System.arraycopy(macKey.getEncoded(), 0, key, SUBKEY_LEN_BYTES, SUBKEY_LEN_BYTES);
// return new Masterkey(key);
// } finally {
// Arrays.fill(key, (byte) 0x00);
// }
// }
//
// @Override
// public Masterkey copy() {
// return new Masterkey(getEncoded());
// }
//
// /**
// * Get the encryption subkey.
// *
// * @return A new copy of the subkey used for encryption
// */
// public DestroyableSecretKey getEncKey() {
// return new DestroyableSecretKey(getEncoded(), 0, SUBKEY_LEN_BYTES, ENC_ALG);
// }
//
// /**
// * Get the MAC subkey.
// *
// * @return A new copy of the subkey used for message authentication
// */
// public DestroyableSecretKey getMacKey() {
// return new DestroyableSecretKey(getEncoded(), SUBKEY_LEN_BYTES, SUBKEY_LEN_BYTES, MAC_ALG);
// }
//
// }
//
// Path: src/main/java/org/cryptomator/cryptolib/api/MasterkeyLoadingFailedException.java
// public class MasterkeyLoadingFailedException extends CryptoException {
//
// public MasterkeyLoadingFailedException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public MasterkeyLoadingFailedException(String message) {
// super(message);
// }
//
// }
// Path: src/main/java/org/cryptomator/cryptolib/common/MasterkeyFileAccess.java
import com.google.common.base.Preconditions;
import org.cryptomator.cryptolib.api.InvalidPassphraseException;
import org.cryptomator.cryptolib.api.Masterkey;
import org.cryptomator.cryptolib.api.MasterkeyLoadingFailedException;
import javax.crypto.Mac;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.Writer;
import java.nio.ByteBuffer;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.nio.file.StandardOpenOption;
import java.security.InvalidKeyException;
import java.security.SecureRandom;
import java.util.Arrays;
import static java.nio.charset.StandardCharsets.UTF_8;
return out.toByteArray();
}
}
public void changePassphrase(InputStream oldIn, OutputStream newOut, CharSequence oldPassphrase, CharSequence newPassphrase) throws IOException, InvalidPassphraseException {
try (Reader reader = new InputStreamReader(oldIn, UTF_8);
Writer writer = new OutputStreamWriter(newOut, UTF_8)) {
MasterkeyFile original = MasterkeyFile.read(reader);
MasterkeyFile updated = changePassphrase(original, oldPassphrase, newPassphrase);
updated.write(writer);
}
}
// visible for testing
MasterkeyFile changePassphrase(MasterkeyFile masterkey, CharSequence oldPassphrase, CharSequence newPassphrase) throws InvalidPassphraseException {
try (Masterkey key = unlock(masterkey, oldPassphrase)) {
return lock(key, newPassphrase, masterkey.version, masterkey.scryptCostParam);
}
}
/**
* Loads the JSON contents from the given file and derives a KEK from the given passphrase to
* unwrap the contained keys.
*
* @param filePath Which file to load
* @param passphrase The passphrase used during key derivation
* @return A new masterkey. Should be used in a try-with-resource statement.
* @throws InvalidPassphraseException If the provided passphrase can not be used to unwrap the stored keys.
* @throws MasterkeyLoadingFailedException If reading the masterkey file fails
*/ | public Masterkey load(Path filePath, CharSequence passphrase) throws MasterkeyLoadingFailedException { |
llbit/ow2-asm | src/org/objectweb/asm/util/Printer.java | // Path: src/org/objectweb/asm/Handle.java
// public final class Handle {
//
// /**
// * The kind of field or method designated by this Handle. Should be
// * {@link Opcodes#H_GETFIELD}, {@link Opcodes#H_GETSTATIC},
// * {@link Opcodes#H_PUTFIELD}, {@link Opcodes#H_PUTSTATIC},
// * {@link Opcodes#H_INVOKEVIRTUAL}, {@link Opcodes#H_INVOKESTATIC},
// * {@link Opcodes#H_INVOKESPECIAL}, {@link Opcodes#H_NEWINVOKESPECIAL} or
// * {@link Opcodes#H_INVOKEINTERFACE}.
// */
// final int tag;
//
// /**
// * The internal name of the field or method designed by this handle.
// */
// final String owner;
//
// /**
// * The name of the field or method designated by this handle.
// */
// final String name;
//
// /**
// * The descriptor of the field or method designated by this handle.
// */
// final String desc;
//
// /**
// * Constructs a new field or method handle.
// *
// * @param tag
// * the kind of field or method designated by this Handle. Must be
// * {@link Opcodes#H_GETFIELD}, {@link Opcodes#H_GETSTATIC},
// * {@link Opcodes#H_PUTFIELD}, {@link Opcodes#H_PUTSTATIC},
// * {@link Opcodes#H_INVOKEVIRTUAL},
// * {@link Opcodes#H_INVOKESTATIC},
// * {@link Opcodes#H_INVOKESPECIAL},
// * {@link Opcodes#H_NEWINVOKESPECIAL} or
// * {@link Opcodes#H_INVOKEINTERFACE}.
// * @param owner
// * the internal name of the field or method designed by this
// * handle.
// * @param name
// * the name of the field or method designated by this handle.
// * @param desc
// * the descriptor of the field or method designated by this
// * handle.
// */
// public Handle(int tag, String owner, String name, String desc) {
// this.tag = tag;
// this.owner = owner;
// this.name = name;
// this.desc = desc;
// }
//
// /**
// * Returns the kind of field or method designated by this handle.
// *
// * @return {@link Opcodes#H_GETFIELD}, {@link Opcodes#H_GETSTATIC},
// * {@link Opcodes#H_PUTFIELD}, {@link Opcodes#H_PUTSTATIC},
// * {@link Opcodes#H_INVOKEVIRTUAL}, {@link Opcodes#H_INVOKESTATIC},
// * {@link Opcodes#H_INVOKESPECIAL},
// * {@link Opcodes#H_NEWINVOKESPECIAL} or
// * {@link Opcodes#H_INVOKEINTERFACE}.
// */
// public int getTag() {
// return tag;
// }
//
// /**
// * Returns the internal name of the field or method designed by this handle.
// *
// * @return the internal name of the field or method designed by this handle.
// */
// public String getOwner() {
// return owner;
// }
//
// /**
// * Returns the name of the field or method designated by this handle.
// *
// * @return the name of the field or method designated by this handle.
// */
// public String getName() {
// return name;
// }
//
// /**
// * Returns the descriptor of the field or method designated by this handle.
// *
// * @return the descriptor of the field or method designated by this handle.
// */
// public String getDesc() {
// return desc;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (obj == this) {
// return true;
// }
// if (!(obj instanceof Handle)) {
// return false;
// }
// Handle h = (Handle) obj;
// return tag == h.tag && owner.equals(h.owner) && name.equals(h.name)
// && desc.equals(h.desc);
// }
//
// @Override
// public int hashCode() {
// return tag + owner.hashCode() * name.hashCode() * desc.hashCode();
// }
//
// /**
// * Returns the textual representation of this handle. The textual
// * representation is:
// *
// * <pre>
// * owner '.' name desc ' ' '(' tag ')'
// * </pre>
// *
// * . As this format is unambiguous, it can be parsed if necessary.
// */
// @Override
// public String toString() {
// return owner + '.' + name + desc + " (" + tag + ')';
// }
// }
| import java.util.ArrayList;
import java.util.List;
import org.objectweb.asm.Attribute;
import org.objectweb.asm.Handle;
import org.objectweb.asm.Label;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.TypePath;
import java.io.PrintWriter; | * Method instruction. See
* {@link org.objectweb.asm.MethodVisitor#visitVarInsn}.
*/
public abstract void visitVarInsn(final int opcode, final int var);
/**
* Method instruction. See
* {@link org.objectweb.asm.MethodVisitor#visitTypeInsn}.
*/
public abstract void visitTypeInsn(final int opcode, final String type);
/**
* Method instruction. See
* {@link org.objectweb.asm.MethodVisitor#visitFieldInsn}.
*/
public abstract void visitFieldInsn(final int opcode, final String owner,
final String name, final String desc);
/**
* Method instruction. See
* {@link org.objectweb.asm.MethodVisitor#visitMethodInsn}.
*/
public abstract void visitMethodInsn(final int opcode, final String owner,
final String name, final String desc);
/**
* Method instruction. See
* {@link org.objectweb.asm.MethodVisitor#visitInvokeDynamicInsn}.
*/
public abstract void visitInvokeDynamicInsn(String name, String desc, | // Path: src/org/objectweb/asm/Handle.java
// public final class Handle {
//
// /**
// * The kind of field or method designated by this Handle. Should be
// * {@link Opcodes#H_GETFIELD}, {@link Opcodes#H_GETSTATIC},
// * {@link Opcodes#H_PUTFIELD}, {@link Opcodes#H_PUTSTATIC},
// * {@link Opcodes#H_INVOKEVIRTUAL}, {@link Opcodes#H_INVOKESTATIC},
// * {@link Opcodes#H_INVOKESPECIAL}, {@link Opcodes#H_NEWINVOKESPECIAL} or
// * {@link Opcodes#H_INVOKEINTERFACE}.
// */
// final int tag;
//
// /**
// * The internal name of the field or method designed by this handle.
// */
// final String owner;
//
// /**
// * The name of the field or method designated by this handle.
// */
// final String name;
//
// /**
// * The descriptor of the field or method designated by this handle.
// */
// final String desc;
//
// /**
// * Constructs a new field or method handle.
// *
// * @param tag
// * the kind of field or method designated by this Handle. Must be
// * {@link Opcodes#H_GETFIELD}, {@link Opcodes#H_GETSTATIC},
// * {@link Opcodes#H_PUTFIELD}, {@link Opcodes#H_PUTSTATIC},
// * {@link Opcodes#H_INVOKEVIRTUAL},
// * {@link Opcodes#H_INVOKESTATIC},
// * {@link Opcodes#H_INVOKESPECIAL},
// * {@link Opcodes#H_NEWINVOKESPECIAL} or
// * {@link Opcodes#H_INVOKEINTERFACE}.
// * @param owner
// * the internal name of the field or method designed by this
// * handle.
// * @param name
// * the name of the field or method designated by this handle.
// * @param desc
// * the descriptor of the field or method designated by this
// * handle.
// */
// public Handle(int tag, String owner, String name, String desc) {
// this.tag = tag;
// this.owner = owner;
// this.name = name;
// this.desc = desc;
// }
//
// /**
// * Returns the kind of field or method designated by this handle.
// *
// * @return {@link Opcodes#H_GETFIELD}, {@link Opcodes#H_GETSTATIC},
// * {@link Opcodes#H_PUTFIELD}, {@link Opcodes#H_PUTSTATIC},
// * {@link Opcodes#H_INVOKEVIRTUAL}, {@link Opcodes#H_INVOKESTATIC},
// * {@link Opcodes#H_INVOKESPECIAL},
// * {@link Opcodes#H_NEWINVOKESPECIAL} or
// * {@link Opcodes#H_INVOKEINTERFACE}.
// */
// public int getTag() {
// return tag;
// }
//
// /**
// * Returns the internal name of the field or method designed by this handle.
// *
// * @return the internal name of the field or method designed by this handle.
// */
// public String getOwner() {
// return owner;
// }
//
// /**
// * Returns the name of the field or method designated by this handle.
// *
// * @return the name of the field or method designated by this handle.
// */
// public String getName() {
// return name;
// }
//
// /**
// * Returns the descriptor of the field or method designated by this handle.
// *
// * @return the descriptor of the field or method designated by this handle.
// */
// public String getDesc() {
// return desc;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (obj == this) {
// return true;
// }
// if (!(obj instanceof Handle)) {
// return false;
// }
// Handle h = (Handle) obj;
// return tag == h.tag && owner.equals(h.owner) && name.equals(h.name)
// && desc.equals(h.desc);
// }
//
// @Override
// public int hashCode() {
// return tag + owner.hashCode() * name.hashCode() * desc.hashCode();
// }
//
// /**
// * Returns the textual representation of this handle. The textual
// * representation is:
// *
// * <pre>
// * owner '.' name desc ' ' '(' tag ')'
// * </pre>
// *
// * . As this format is unambiguous, it can be parsed if necessary.
// */
// @Override
// public String toString() {
// return owner + '.' + name + desc + " (" + tag + ')';
// }
// }
// Path: src/org/objectweb/asm/util/Printer.java
import java.util.ArrayList;
import java.util.List;
import org.objectweb.asm.Attribute;
import org.objectweb.asm.Handle;
import org.objectweb.asm.Label;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.TypePath;
import java.io.PrintWriter;
* Method instruction. See
* {@link org.objectweb.asm.MethodVisitor#visitVarInsn}.
*/
public abstract void visitVarInsn(final int opcode, final int var);
/**
* Method instruction. See
* {@link org.objectweb.asm.MethodVisitor#visitTypeInsn}.
*/
public abstract void visitTypeInsn(final int opcode, final String type);
/**
* Method instruction. See
* {@link org.objectweb.asm.MethodVisitor#visitFieldInsn}.
*/
public abstract void visitFieldInsn(final int opcode, final String owner,
final String name, final String desc);
/**
* Method instruction. See
* {@link org.objectweb.asm.MethodVisitor#visitMethodInsn}.
*/
public abstract void visitMethodInsn(final int opcode, final String owner,
final String name, final String desc);
/**
* Method instruction. See
* {@link org.objectweb.asm.MethodVisitor#visitInvokeDynamicInsn}.
*/
public abstract void visitInvokeDynamicInsn(String name, String desc, | Handle bsm, Object... bsmArgs); |
llbit/ow2-asm | test/conform/org/objectweb/asm/ClassWriterResizeInsnsTest.java | // Path: test/conform/org/objectweb/asm/attrs/CodeComment.java
// public class CodeComment extends Attribute implements ASMifiable, Textifiable {
//
// public CodeComment() {
// super("CodeComment");
// }
//
// @Override
// public boolean isUnknown() {
// return false;
// }
//
// @Override
// public boolean isCodeAttribute() {
// return true;
// }
//
// @Override
// protected Attribute read(final ClassReader cr, final int off,
// final int len, final char[] buf, final int codeOff,
// final Label[] labels) {
//
// return new CodeComment();
// }
//
// @Override
// protected ByteVector write(final ClassWriter cw, final byte[] code,
// final int len, final int maxStack, final int maxLocals) {
// return new ByteVector();
// }
//
// @Override
// protected Label[] getLabels() {
// super.getLabels();
// return new Label[] { new Label() };
// }
//
// public void asmify(final StringBuffer buf, final String varName,
// final Map<Label, String> labelNames) {
// buf.append("Attribute ").append(varName)
// .append(" = new org.objectweb.asm.attrs.CodeComment();");
// }
//
// public void textify(final StringBuffer buf,
// final Map<Label, String> labelNames) {
// }
// }
| import java.lang.instrument.IllegalClassFormatException;
import java.lang.instrument.Instrumentation;
import java.security.ProtectionDomain;
import java.util.HashSet;
import junit.framework.TestSuite;
import org.objectweb.asm.attrs.CodeComment;
import java.lang.instrument.ClassFileTransformer; | @Override
public MethodVisitor visitMethod(final int access,
final String name, final String desc,
final String signature, final String[] exceptions) {
return new MethodVisitor(Opcodes.ASM5, cv.visitMethod(access,
name, desc, signature, exceptions)) {
private final HashSet<Label> labels = new HashSet<Label>();
@Override
public void visitLabel(final Label label) {
super.visitLabel(label);
labels.add(label);
}
@Override
public void visitJumpInsn(final int opcode,
final Label label) {
super.visitJumpInsn(opcode, label);
if (opcode != Opcodes.GOTO) {
if (!transformed && !labels.contains(label)) {
transformed = true;
for (int i = 0; i < 33000; ++i) {
mv.visitInsn(Opcodes.NOP);
}
}
}
}
};
}
}; | // Path: test/conform/org/objectweb/asm/attrs/CodeComment.java
// public class CodeComment extends Attribute implements ASMifiable, Textifiable {
//
// public CodeComment() {
// super("CodeComment");
// }
//
// @Override
// public boolean isUnknown() {
// return false;
// }
//
// @Override
// public boolean isCodeAttribute() {
// return true;
// }
//
// @Override
// protected Attribute read(final ClassReader cr, final int off,
// final int len, final char[] buf, final int codeOff,
// final Label[] labels) {
//
// return new CodeComment();
// }
//
// @Override
// protected ByteVector write(final ClassWriter cw, final byte[] code,
// final int len, final int maxStack, final int maxLocals) {
// return new ByteVector();
// }
//
// @Override
// protected Label[] getLabels() {
// super.getLabels();
// return new Label[] { new Label() };
// }
//
// public void asmify(final StringBuffer buf, final String varName,
// final Map<Label, String> labelNames) {
// buf.append("Attribute ").append(varName)
// .append(" = new org.objectweb.asm.attrs.CodeComment();");
// }
//
// public void textify(final StringBuffer buf,
// final Map<Label, String> labelNames) {
// }
// }
// Path: test/conform/org/objectweb/asm/ClassWriterResizeInsnsTest.java
import java.lang.instrument.IllegalClassFormatException;
import java.lang.instrument.Instrumentation;
import java.security.ProtectionDomain;
import java.util.HashSet;
import junit.framework.TestSuite;
import org.objectweb.asm.attrs.CodeComment;
import java.lang.instrument.ClassFileTransformer;
@Override
public MethodVisitor visitMethod(final int access,
final String name, final String desc,
final String signature, final String[] exceptions) {
return new MethodVisitor(Opcodes.ASM5, cv.visitMethod(access,
name, desc, signature, exceptions)) {
private final HashSet<Label> labels = new HashSet<Label>();
@Override
public void visitLabel(final Label label) {
super.visitLabel(label);
labels.add(label);
}
@Override
public void visitJumpInsn(final int opcode,
final Label label) {
super.visitJumpInsn(opcode, label);
if (opcode != Opcodes.GOTO) {
if (!transformed && !labels.contains(label)) {
transformed = true;
for (int i = 0; i < 33000; ++i) {
mv.visitInsn(Opcodes.NOP);
}
}
}
}
};
}
}; | cr.accept(ca, new Attribute[] { new CodeComment() }, 0); |
llbit/ow2-asm | src/org/objectweb/asm/tree/analysis/SourceInterpreter.java | // Path: src/org/objectweb/asm/tree/InvokeDynamicInsnNode.java
// public class InvokeDynamicInsnNode extends AbstractInsnNode {
//
// /**
// * Invokedynamic name.
// */
// public String name;
//
// /**
// * Invokedynamic descriptor.
// */
// public String desc;
//
// /**
// * Bootstrap method
// */
// public Handle bsm;
//
// /**
// * Bootstrap constant arguments
// */
// public Object[] bsmArgs;
//
// /**
// * Constructs a new {@link InvokeDynamicInsnNode}.
// *
// * @param name
// * invokedynamic name.
// * @param desc
// * invokedynamic descriptor (see {@link org.objectweb.asm.Type}).
// * @param bsm
// * the bootstrap method.
// * @param bsmArgs
// * the boostrap constant arguments.
// */
// public InvokeDynamicInsnNode(final String name, final String desc,
// final Handle bsm, final Object... bsmArgs) {
// super(Opcodes.INVOKEDYNAMIC);
// this.name = name;
// this.desc = desc;
// this.bsm = bsm;
// this.bsmArgs = bsmArgs;
// }
//
// @Override
// public int getType() {
// return INVOKE_DYNAMIC_INSN;
// }
//
// @Override
// public void accept(final MethodVisitor mv) {
// mv.visitInvokeDynamicInsn(name, desc, bsm, bsmArgs);
// acceptAnnotations(mv);
// }
//
// @Override
// public AbstractInsnNode clone(final Map<LabelNode, LabelNode> labels) {
// return new InvokeDynamicInsnNode(name, desc, bsm, bsmArgs)
// .cloneAnnotations(this);
// }
// }
| import java.util.List;
import java.util.Set;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.FieldInsnNode;
import org.objectweb.asm.tree.InvokeDynamicInsnNode;
import org.objectweb.asm.tree.LdcInsnNode;
import org.objectweb.asm.tree.MethodInsnNode;
import java.util.HashSet; | case DREM:
case LSHL:
case LSHR:
case LUSHR:
case LAND:
case LOR:
case LXOR:
size = 2;
break;
default:
size = 1;
}
return new SourceValue(size, insn);
}
@Override
public SourceValue ternaryOperation(final AbstractInsnNode insn,
final SourceValue value1, final SourceValue value2,
final SourceValue value3) {
return new SourceValue(1, insn);
}
@Override
public SourceValue naryOperation(final AbstractInsnNode insn,
final List<? extends SourceValue> values) {
int size;
int opcode = insn.getOpcode();
if (opcode == MULTIANEWARRAY) {
size = 1;
} else { | // Path: src/org/objectweb/asm/tree/InvokeDynamicInsnNode.java
// public class InvokeDynamicInsnNode extends AbstractInsnNode {
//
// /**
// * Invokedynamic name.
// */
// public String name;
//
// /**
// * Invokedynamic descriptor.
// */
// public String desc;
//
// /**
// * Bootstrap method
// */
// public Handle bsm;
//
// /**
// * Bootstrap constant arguments
// */
// public Object[] bsmArgs;
//
// /**
// * Constructs a new {@link InvokeDynamicInsnNode}.
// *
// * @param name
// * invokedynamic name.
// * @param desc
// * invokedynamic descriptor (see {@link org.objectweb.asm.Type}).
// * @param bsm
// * the bootstrap method.
// * @param bsmArgs
// * the boostrap constant arguments.
// */
// public InvokeDynamicInsnNode(final String name, final String desc,
// final Handle bsm, final Object... bsmArgs) {
// super(Opcodes.INVOKEDYNAMIC);
// this.name = name;
// this.desc = desc;
// this.bsm = bsm;
// this.bsmArgs = bsmArgs;
// }
//
// @Override
// public int getType() {
// return INVOKE_DYNAMIC_INSN;
// }
//
// @Override
// public void accept(final MethodVisitor mv) {
// mv.visitInvokeDynamicInsn(name, desc, bsm, bsmArgs);
// acceptAnnotations(mv);
// }
//
// @Override
// public AbstractInsnNode clone(final Map<LabelNode, LabelNode> labels) {
// return new InvokeDynamicInsnNode(name, desc, bsm, bsmArgs)
// .cloneAnnotations(this);
// }
// }
// Path: src/org/objectweb/asm/tree/analysis/SourceInterpreter.java
import java.util.List;
import java.util.Set;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.FieldInsnNode;
import org.objectweb.asm.tree.InvokeDynamicInsnNode;
import org.objectweb.asm.tree.LdcInsnNode;
import org.objectweb.asm.tree.MethodInsnNode;
import java.util.HashSet;
case DREM:
case LSHL:
case LSHR:
case LUSHR:
case LAND:
case LOR:
case LXOR:
size = 2;
break;
default:
size = 1;
}
return new SourceValue(size, insn);
}
@Override
public SourceValue ternaryOperation(final AbstractInsnNode insn,
final SourceValue value1, final SourceValue value2,
final SourceValue value3) {
return new SourceValue(1, insn);
}
@Override
public SourceValue naryOperation(final AbstractInsnNode insn,
final List<? extends SourceValue> values) {
int size;
int opcode = insn.getOpcode();
if (opcode == MULTIANEWARRAY) {
size = 1;
} else { | String desc = (opcode == INVOKEDYNAMIC) ? ((InvokeDynamicInsnNode) insn).desc |
llbit/ow2-asm | test/conform/org/objectweb/asm/tree/ClassNodeUnitTest.java | // Path: src/org/objectweb/asm/Handle.java
// public final class Handle {
//
// /**
// * The kind of field or method designated by this Handle. Should be
// * {@link Opcodes#H_GETFIELD}, {@link Opcodes#H_GETSTATIC},
// * {@link Opcodes#H_PUTFIELD}, {@link Opcodes#H_PUTSTATIC},
// * {@link Opcodes#H_INVOKEVIRTUAL}, {@link Opcodes#H_INVOKESTATIC},
// * {@link Opcodes#H_INVOKESPECIAL}, {@link Opcodes#H_NEWINVOKESPECIAL} or
// * {@link Opcodes#H_INVOKEINTERFACE}.
// */
// final int tag;
//
// /**
// * The internal name of the field or method designed by this handle.
// */
// final String owner;
//
// /**
// * The name of the field or method designated by this handle.
// */
// final String name;
//
// /**
// * The descriptor of the field or method designated by this handle.
// */
// final String desc;
//
// /**
// * Constructs a new field or method handle.
// *
// * @param tag
// * the kind of field or method designated by this Handle. Must be
// * {@link Opcodes#H_GETFIELD}, {@link Opcodes#H_GETSTATIC},
// * {@link Opcodes#H_PUTFIELD}, {@link Opcodes#H_PUTSTATIC},
// * {@link Opcodes#H_INVOKEVIRTUAL},
// * {@link Opcodes#H_INVOKESTATIC},
// * {@link Opcodes#H_INVOKESPECIAL},
// * {@link Opcodes#H_NEWINVOKESPECIAL} or
// * {@link Opcodes#H_INVOKEINTERFACE}.
// * @param owner
// * the internal name of the field or method designed by this
// * handle.
// * @param name
// * the name of the field or method designated by this handle.
// * @param desc
// * the descriptor of the field or method designated by this
// * handle.
// */
// public Handle(int tag, String owner, String name, String desc) {
// this.tag = tag;
// this.owner = owner;
// this.name = name;
// this.desc = desc;
// }
//
// /**
// * Returns the kind of field or method designated by this handle.
// *
// * @return {@link Opcodes#H_GETFIELD}, {@link Opcodes#H_GETSTATIC},
// * {@link Opcodes#H_PUTFIELD}, {@link Opcodes#H_PUTSTATIC},
// * {@link Opcodes#H_INVOKEVIRTUAL}, {@link Opcodes#H_INVOKESTATIC},
// * {@link Opcodes#H_INVOKESPECIAL},
// * {@link Opcodes#H_NEWINVOKESPECIAL} or
// * {@link Opcodes#H_INVOKEINTERFACE}.
// */
// public int getTag() {
// return tag;
// }
//
// /**
// * Returns the internal name of the field or method designed by this handle.
// *
// * @return the internal name of the field or method designed by this handle.
// */
// public String getOwner() {
// return owner;
// }
//
// /**
// * Returns the name of the field or method designated by this handle.
// *
// * @return the name of the field or method designated by this handle.
// */
// public String getName() {
// return name;
// }
//
// /**
// * Returns the descriptor of the field or method designated by this handle.
// *
// * @return the descriptor of the field or method designated by this handle.
// */
// public String getDesc() {
// return desc;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (obj == this) {
// return true;
// }
// if (!(obj instanceof Handle)) {
// return false;
// }
// Handle h = (Handle) obj;
// return tag == h.tag && owner.equals(h.owner) && name.equals(h.name)
// && desc.equals(h.desc);
// }
//
// @Override
// public int hashCode() {
// return tag + owner.hashCode() * name.hashCode() * desc.hashCode();
// }
//
// /**
// * Returns the textual representation of this handle. The textual
// * representation is:
// *
// * <pre>
// * owner '.' name desc ' ' '(' tag ')'
// * </pre>
// *
// * . As this format is unambiguous, it can be parsed if necessary.
// */
// @Override
// public String toString() {
// return owner + '.' + name + desc + " (" + tag + ')';
// }
// }
| import org.objectweb.asm.Handle;
import org.objectweb.asm.Label;
import org.objectweb.asm.Opcodes;
import junit.framework.TestCase; | public void testVarInsnNode() {
VarInsnNode vn = new VarInsnNode(ALOAD, 0);
vn.setOpcode(ASTORE);
assertEquals(ASTORE, vn.getOpcode());
assertEquals(AbstractInsnNode.VAR_INSN, vn.getType());
}
public void testTypeInsnNode() {
TypeInsnNode tin = new TypeInsnNode(NEW, "java/lang/Object");
tin.setOpcode(CHECKCAST);
assertEquals(CHECKCAST, tin.getOpcode());
assertEquals(AbstractInsnNode.TYPE_INSN, tin.getType());
}
public void testFieldInsnNode() {
FieldInsnNode fn = new FieldInsnNode(GETSTATIC, "owner", "name", "I");
fn.setOpcode(PUTSTATIC);
assertEquals(PUTSTATIC, fn.getOpcode());
assertEquals(AbstractInsnNode.FIELD_INSN, fn.getType());
}
public void testMethodInsnNode() {
MethodInsnNode mn = new MethodInsnNode(INVOKESTATIC, "owner", "name",
"I");
mn.setOpcode(INVOKESPECIAL);
assertEquals(INVOKESPECIAL, mn.getOpcode());
assertEquals(AbstractInsnNode.METHOD_INSN, mn.getType());
}
public void testInvokeDynamicInsnNode() { | // Path: src/org/objectweb/asm/Handle.java
// public final class Handle {
//
// /**
// * The kind of field or method designated by this Handle. Should be
// * {@link Opcodes#H_GETFIELD}, {@link Opcodes#H_GETSTATIC},
// * {@link Opcodes#H_PUTFIELD}, {@link Opcodes#H_PUTSTATIC},
// * {@link Opcodes#H_INVOKEVIRTUAL}, {@link Opcodes#H_INVOKESTATIC},
// * {@link Opcodes#H_INVOKESPECIAL}, {@link Opcodes#H_NEWINVOKESPECIAL} or
// * {@link Opcodes#H_INVOKEINTERFACE}.
// */
// final int tag;
//
// /**
// * The internal name of the field or method designed by this handle.
// */
// final String owner;
//
// /**
// * The name of the field or method designated by this handle.
// */
// final String name;
//
// /**
// * The descriptor of the field or method designated by this handle.
// */
// final String desc;
//
// /**
// * Constructs a new field or method handle.
// *
// * @param tag
// * the kind of field or method designated by this Handle. Must be
// * {@link Opcodes#H_GETFIELD}, {@link Opcodes#H_GETSTATIC},
// * {@link Opcodes#H_PUTFIELD}, {@link Opcodes#H_PUTSTATIC},
// * {@link Opcodes#H_INVOKEVIRTUAL},
// * {@link Opcodes#H_INVOKESTATIC},
// * {@link Opcodes#H_INVOKESPECIAL},
// * {@link Opcodes#H_NEWINVOKESPECIAL} or
// * {@link Opcodes#H_INVOKEINTERFACE}.
// * @param owner
// * the internal name of the field or method designed by this
// * handle.
// * @param name
// * the name of the field or method designated by this handle.
// * @param desc
// * the descriptor of the field or method designated by this
// * handle.
// */
// public Handle(int tag, String owner, String name, String desc) {
// this.tag = tag;
// this.owner = owner;
// this.name = name;
// this.desc = desc;
// }
//
// /**
// * Returns the kind of field or method designated by this handle.
// *
// * @return {@link Opcodes#H_GETFIELD}, {@link Opcodes#H_GETSTATIC},
// * {@link Opcodes#H_PUTFIELD}, {@link Opcodes#H_PUTSTATIC},
// * {@link Opcodes#H_INVOKEVIRTUAL}, {@link Opcodes#H_INVOKESTATIC},
// * {@link Opcodes#H_INVOKESPECIAL},
// * {@link Opcodes#H_NEWINVOKESPECIAL} or
// * {@link Opcodes#H_INVOKEINTERFACE}.
// */
// public int getTag() {
// return tag;
// }
//
// /**
// * Returns the internal name of the field or method designed by this handle.
// *
// * @return the internal name of the field or method designed by this handle.
// */
// public String getOwner() {
// return owner;
// }
//
// /**
// * Returns the name of the field or method designated by this handle.
// *
// * @return the name of the field or method designated by this handle.
// */
// public String getName() {
// return name;
// }
//
// /**
// * Returns the descriptor of the field or method designated by this handle.
// *
// * @return the descriptor of the field or method designated by this handle.
// */
// public String getDesc() {
// return desc;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (obj == this) {
// return true;
// }
// if (!(obj instanceof Handle)) {
// return false;
// }
// Handle h = (Handle) obj;
// return tag == h.tag && owner.equals(h.owner) && name.equals(h.name)
// && desc.equals(h.desc);
// }
//
// @Override
// public int hashCode() {
// return tag + owner.hashCode() * name.hashCode() * desc.hashCode();
// }
//
// /**
// * Returns the textual representation of this handle. The textual
// * representation is:
// *
// * <pre>
// * owner '.' name desc ' ' '(' tag ')'
// * </pre>
// *
// * . As this format is unambiguous, it can be parsed if necessary.
// */
// @Override
// public String toString() {
// return owner + '.' + name + desc + " (" + tag + ')';
// }
// }
// Path: test/conform/org/objectweb/asm/tree/ClassNodeUnitTest.java
import org.objectweb.asm.Handle;
import org.objectweb.asm.Label;
import org.objectweb.asm.Opcodes;
import junit.framework.TestCase;
public void testVarInsnNode() {
VarInsnNode vn = new VarInsnNode(ALOAD, 0);
vn.setOpcode(ASTORE);
assertEquals(ASTORE, vn.getOpcode());
assertEquals(AbstractInsnNode.VAR_INSN, vn.getType());
}
public void testTypeInsnNode() {
TypeInsnNode tin = new TypeInsnNode(NEW, "java/lang/Object");
tin.setOpcode(CHECKCAST);
assertEquals(CHECKCAST, tin.getOpcode());
assertEquals(AbstractInsnNode.TYPE_INSN, tin.getType());
}
public void testFieldInsnNode() {
FieldInsnNode fn = new FieldInsnNode(GETSTATIC, "owner", "name", "I");
fn.setOpcode(PUTSTATIC);
assertEquals(PUTSTATIC, fn.getOpcode());
assertEquals(AbstractInsnNode.FIELD_INSN, fn.getType());
}
public void testMethodInsnNode() {
MethodInsnNode mn = new MethodInsnNode(INVOKESTATIC, "owner", "name",
"I");
mn.setOpcode(INVOKESPECIAL);
assertEquals(INVOKESPECIAL, mn.getOpcode());
assertEquals(AbstractInsnNode.METHOD_INSN, mn.getType());
}
public void testInvokeDynamicInsnNode() { | Handle bsm = new Handle(Opcodes.H_INVOKESTATIC, "owner", "name", "()V"); |
llbit/ow2-asm | src/org/objectweb/asm/tree/analysis/BasicVerifier.java | // Path: src/org/objectweb/asm/tree/InvokeDynamicInsnNode.java
// public class InvokeDynamicInsnNode extends AbstractInsnNode {
//
// /**
// * Invokedynamic name.
// */
// public String name;
//
// /**
// * Invokedynamic descriptor.
// */
// public String desc;
//
// /**
// * Bootstrap method
// */
// public Handle bsm;
//
// /**
// * Bootstrap constant arguments
// */
// public Object[] bsmArgs;
//
// /**
// * Constructs a new {@link InvokeDynamicInsnNode}.
// *
// * @param name
// * invokedynamic name.
// * @param desc
// * invokedynamic descriptor (see {@link org.objectweb.asm.Type}).
// * @param bsm
// * the bootstrap method.
// * @param bsmArgs
// * the boostrap constant arguments.
// */
// public InvokeDynamicInsnNode(final String name, final String desc,
// final Handle bsm, final Object... bsmArgs) {
// super(Opcodes.INVOKEDYNAMIC);
// this.name = name;
// this.desc = desc;
// this.bsm = bsm;
// this.bsmArgs = bsmArgs;
// }
//
// @Override
// public int getType() {
// return INVOKE_DYNAMIC_INSN;
// }
//
// @Override
// public void accept(final MethodVisitor mv) {
// mv.visitInvokeDynamicInsn(name, desc, bsm, bsmArgs);
// acceptAnnotations(mv);
// }
//
// @Override
// public AbstractInsnNode clone(final Map<LabelNode, LabelNode> labels) {
// return new InvokeDynamicInsnNode(name, desc, bsm, bsmArgs)
// .cloneAnnotations(this);
// }
// }
| import org.objectweb.asm.Type;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.FieldInsnNode;
import org.objectweb.asm.tree.InvokeDynamicInsnNode;
import org.objectweb.asm.tree.MethodInsnNode;
import java.util.List; | throw new AnalyzerException(insn, "Second argument",
BasicValue.INT_VALUE, value2);
} else if (!isSubTypeOf(value3, expected3)) {
throw new AnalyzerException(insn, "Third argument", expected3,
value3);
}
return null;
}
@Override
public BasicValue naryOperation(final AbstractInsnNode insn,
final List<? extends BasicValue> values) throws AnalyzerException {
int opcode = insn.getOpcode();
if (opcode == MULTIANEWARRAY) {
for (int i = 0; i < values.size(); ++i) {
if (!BasicValue.INT_VALUE.equals(values.get(i))) {
throw new AnalyzerException(insn, null,
BasicValue.INT_VALUE, values.get(i));
}
}
} else {
int i = 0;
int j = 0;
if (opcode != INVOKESTATIC && opcode != INVOKEDYNAMIC) {
Type owner = Type.getObjectType(((MethodInsnNode) insn).owner);
if (!isSubTypeOf(values.get(i++), newValue(owner))) {
throw new AnalyzerException(insn, "Method owner",
newValue(owner), values.get(0));
}
} | // Path: src/org/objectweb/asm/tree/InvokeDynamicInsnNode.java
// public class InvokeDynamicInsnNode extends AbstractInsnNode {
//
// /**
// * Invokedynamic name.
// */
// public String name;
//
// /**
// * Invokedynamic descriptor.
// */
// public String desc;
//
// /**
// * Bootstrap method
// */
// public Handle bsm;
//
// /**
// * Bootstrap constant arguments
// */
// public Object[] bsmArgs;
//
// /**
// * Constructs a new {@link InvokeDynamicInsnNode}.
// *
// * @param name
// * invokedynamic name.
// * @param desc
// * invokedynamic descriptor (see {@link org.objectweb.asm.Type}).
// * @param bsm
// * the bootstrap method.
// * @param bsmArgs
// * the boostrap constant arguments.
// */
// public InvokeDynamicInsnNode(final String name, final String desc,
// final Handle bsm, final Object... bsmArgs) {
// super(Opcodes.INVOKEDYNAMIC);
// this.name = name;
// this.desc = desc;
// this.bsm = bsm;
// this.bsmArgs = bsmArgs;
// }
//
// @Override
// public int getType() {
// return INVOKE_DYNAMIC_INSN;
// }
//
// @Override
// public void accept(final MethodVisitor mv) {
// mv.visitInvokeDynamicInsn(name, desc, bsm, bsmArgs);
// acceptAnnotations(mv);
// }
//
// @Override
// public AbstractInsnNode clone(final Map<LabelNode, LabelNode> labels) {
// return new InvokeDynamicInsnNode(name, desc, bsm, bsmArgs)
// .cloneAnnotations(this);
// }
// }
// Path: src/org/objectweb/asm/tree/analysis/BasicVerifier.java
import org.objectweb.asm.Type;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.FieldInsnNode;
import org.objectweb.asm.tree.InvokeDynamicInsnNode;
import org.objectweb.asm.tree.MethodInsnNode;
import java.util.List;
throw new AnalyzerException(insn, "Second argument",
BasicValue.INT_VALUE, value2);
} else if (!isSubTypeOf(value3, expected3)) {
throw new AnalyzerException(insn, "Third argument", expected3,
value3);
}
return null;
}
@Override
public BasicValue naryOperation(final AbstractInsnNode insn,
final List<? extends BasicValue> values) throws AnalyzerException {
int opcode = insn.getOpcode();
if (opcode == MULTIANEWARRAY) {
for (int i = 0; i < values.size(); ++i) {
if (!BasicValue.INT_VALUE.equals(values.get(i))) {
throw new AnalyzerException(insn, null,
BasicValue.INT_VALUE, values.get(i));
}
}
} else {
int i = 0;
int j = 0;
if (opcode != INVOKESTATIC && opcode != INVOKEDYNAMIC) {
Type owner = Type.getObjectType(((MethodInsnNode) insn).owner);
if (!isSubTypeOf(values.get(i++), newValue(owner))) {
throw new AnalyzerException(insn, "Method owner",
newValue(owner), values.get(0));
}
} | String desc = (opcode == INVOKEDYNAMIC) ? ((InvokeDynamicInsnNode) insn).desc |
kwon37xi/hibernate4-memcached | hibernate4-memcached-core/src/test/java/kr/pe/kwonnam/hibernate4memcached/FakeMemcachedAdapter.java | // Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/memcached/CacheNamespace.java
// public class CacheNamespace implements Serializable {
// /**
// * name of region
// */
// private String name;
//
// /**
// * if this value is true, the memcached adapter should implement namespace pattern
// * or ignore namespace pattern.
// * <p/>
// * see <a href="https://code.google.com/p/memcached/wiki/NewProgrammingTricks#Namespacing">Memcached Namespacing</a>
// */
// private boolean namespaceExpirationRequired;
//
// public CacheNamespace(String name, boolean namespaceExpirationRequired) {
// this.name = name;
// this.namespaceExpirationRequired = namespaceExpirationRequired;
// }
//
// public String getName() {
// return name;
// }
//
// public boolean isNamespaceExpirationRequired() {
// return namespaceExpirationRequired;
// }
//
// @Override
// public boolean equals(Object o) {
// if (o == null) {
// return false;
// }
// if (this == o) {
// return true;
// }
// if (getClass() != o.getClass()) {
// return false;
// }
//
// CacheNamespace otherCacheNamespace = (CacheNamespace) o;
//
// return new EqualsBuilder().append(name, otherCacheNamespace.name)
// .append(namespaceExpirationRequired, otherCacheNamespace.namespaceExpirationRequired).isEquals();
// }
//
// @Override
// public int hashCode() {
// return new HashCodeBuilder().append(name).append(namespaceExpirationRequired).toHashCode();
// }
//
// @Override
// public String toString() {
// return new ToStringBuilder(this).append("name", name).append("namespaceExpirationRequired", namespaceExpirationRequired).toString();
// }
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/memcached/MemcachedAdapter.java
// public interface MemcachedAdapter {
// /**
// * Lifecycle callback to perform initialization.
// *
// * @param properties the defined cfg properties
// */
// void init(OverridableReadOnlyProperties properties);
//
// /**
// * Lifecycle callback to perform cleanup.
// */
// void destroy();
//
// /**
// * get value from memcached
// */
// Object get(CacheNamespace cacheNamespace, String key);
//
// /**
// * set value to memcache with expirySeconds
// */
// void set(CacheNamespace cacheNamespace, String key, Object value, int expirySeconds);
//
// /**
// * delete key from memcached
// */
// void delete(CacheNamespace cacheNamespace, String key);
//
// /**
// * increase given increment couter and return new value.
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param by the amount of increment
// * @param defaultValue default value when the key missing
// * @return increased value
// */
// long increaseCounter(CacheNamespace cacheNamespace, String key, long by, long defaultValue, int expirySeconds);
//
// /**
// * get current value from increment counter
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param defaultValue default value when the key missing
// * @return current value of counter without increment
// */
// long getCounter(CacheNamespace cacheNamespace, String key, long defaultValue, int expirySeconds);
//
// /**
// * Evict namespace
// *
// * @param cacheNamespace cache namespace
// */
// void evictAll(CacheNamespace cacheNamespace);
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/util/OverridableReadOnlyProperties.java
// public interface OverridableReadOnlyProperties {
// String getProperty(String key);
//
// String getProperty(String key, String defaultValue);
//
// String getRequiredProperty(String key);
// }
| import kr.pe.kwonnam.hibernate4memcached.memcached.CacheNamespace;
import kr.pe.kwonnam.hibernate4memcached.memcached.MemcachedAdapter;
import kr.pe.kwonnam.hibernate4memcached.util.OverridableReadOnlyProperties; | package kr.pe.kwonnam.hibernate4memcached;
/**
* @author KwonNam Son ([email protected])
*/
public class FakeMemcachedAdapter implements MemcachedAdapter {
boolean initCalled = false;
public boolean isInitCalled() {
return initCalled;
}
@Override | // Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/memcached/CacheNamespace.java
// public class CacheNamespace implements Serializable {
// /**
// * name of region
// */
// private String name;
//
// /**
// * if this value is true, the memcached adapter should implement namespace pattern
// * or ignore namespace pattern.
// * <p/>
// * see <a href="https://code.google.com/p/memcached/wiki/NewProgrammingTricks#Namespacing">Memcached Namespacing</a>
// */
// private boolean namespaceExpirationRequired;
//
// public CacheNamespace(String name, boolean namespaceExpirationRequired) {
// this.name = name;
// this.namespaceExpirationRequired = namespaceExpirationRequired;
// }
//
// public String getName() {
// return name;
// }
//
// public boolean isNamespaceExpirationRequired() {
// return namespaceExpirationRequired;
// }
//
// @Override
// public boolean equals(Object o) {
// if (o == null) {
// return false;
// }
// if (this == o) {
// return true;
// }
// if (getClass() != o.getClass()) {
// return false;
// }
//
// CacheNamespace otherCacheNamespace = (CacheNamespace) o;
//
// return new EqualsBuilder().append(name, otherCacheNamespace.name)
// .append(namespaceExpirationRequired, otherCacheNamespace.namespaceExpirationRequired).isEquals();
// }
//
// @Override
// public int hashCode() {
// return new HashCodeBuilder().append(name).append(namespaceExpirationRequired).toHashCode();
// }
//
// @Override
// public String toString() {
// return new ToStringBuilder(this).append("name", name).append("namespaceExpirationRequired", namespaceExpirationRequired).toString();
// }
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/memcached/MemcachedAdapter.java
// public interface MemcachedAdapter {
// /**
// * Lifecycle callback to perform initialization.
// *
// * @param properties the defined cfg properties
// */
// void init(OverridableReadOnlyProperties properties);
//
// /**
// * Lifecycle callback to perform cleanup.
// */
// void destroy();
//
// /**
// * get value from memcached
// */
// Object get(CacheNamespace cacheNamespace, String key);
//
// /**
// * set value to memcache with expirySeconds
// */
// void set(CacheNamespace cacheNamespace, String key, Object value, int expirySeconds);
//
// /**
// * delete key from memcached
// */
// void delete(CacheNamespace cacheNamespace, String key);
//
// /**
// * increase given increment couter and return new value.
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param by the amount of increment
// * @param defaultValue default value when the key missing
// * @return increased value
// */
// long increaseCounter(CacheNamespace cacheNamespace, String key, long by, long defaultValue, int expirySeconds);
//
// /**
// * get current value from increment counter
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param defaultValue default value when the key missing
// * @return current value of counter without increment
// */
// long getCounter(CacheNamespace cacheNamespace, String key, long defaultValue, int expirySeconds);
//
// /**
// * Evict namespace
// *
// * @param cacheNamespace cache namespace
// */
// void evictAll(CacheNamespace cacheNamespace);
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/util/OverridableReadOnlyProperties.java
// public interface OverridableReadOnlyProperties {
// String getProperty(String key);
//
// String getProperty(String key, String defaultValue);
//
// String getRequiredProperty(String key);
// }
// Path: hibernate4-memcached-core/src/test/java/kr/pe/kwonnam/hibernate4memcached/FakeMemcachedAdapter.java
import kr.pe.kwonnam.hibernate4memcached.memcached.CacheNamespace;
import kr.pe.kwonnam.hibernate4memcached.memcached.MemcachedAdapter;
import kr.pe.kwonnam.hibernate4memcached.util.OverridableReadOnlyProperties;
package kr.pe.kwonnam.hibernate4memcached;
/**
* @author KwonNam Son ([email protected])
*/
public class FakeMemcachedAdapter implements MemcachedAdapter {
boolean initCalled = false;
public boolean isInitCalled() {
return initCalled;
}
@Override | public void init(OverridableReadOnlyProperties properties) { |
kwon37xi/hibernate4-memcached | hibernate4-memcached-core/src/test/java/kr/pe/kwonnam/hibernate4memcached/FakeMemcachedAdapter.java | // Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/memcached/CacheNamespace.java
// public class CacheNamespace implements Serializable {
// /**
// * name of region
// */
// private String name;
//
// /**
// * if this value is true, the memcached adapter should implement namespace pattern
// * or ignore namespace pattern.
// * <p/>
// * see <a href="https://code.google.com/p/memcached/wiki/NewProgrammingTricks#Namespacing">Memcached Namespacing</a>
// */
// private boolean namespaceExpirationRequired;
//
// public CacheNamespace(String name, boolean namespaceExpirationRequired) {
// this.name = name;
// this.namespaceExpirationRequired = namespaceExpirationRequired;
// }
//
// public String getName() {
// return name;
// }
//
// public boolean isNamespaceExpirationRequired() {
// return namespaceExpirationRequired;
// }
//
// @Override
// public boolean equals(Object o) {
// if (o == null) {
// return false;
// }
// if (this == o) {
// return true;
// }
// if (getClass() != o.getClass()) {
// return false;
// }
//
// CacheNamespace otherCacheNamespace = (CacheNamespace) o;
//
// return new EqualsBuilder().append(name, otherCacheNamespace.name)
// .append(namespaceExpirationRequired, otherCacheNamespace.namespaceExpirationRequired).isEquals();
// }
//
// @Override
// public int hashCode() {
// return new HashCodeBuilder().append(name).append(namespaceExpirationRequired).toHashCode();
// }
//
// @Override
// public String toString() {
// return new ToStringBuilder(this).append("name", name).append("namespaceExpirationRequired", namespaceExpirationRequired).toString();
// }
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/memcached/MemcachedAdapter.java
// public interface MemcachedAdapter {
// /**
// * Lifecycle callback to perform initialization.
// *
// * @param properties the defined cfg properties
// */
// void init(OverridableReadOnlyProperties properties);
//
// /**
// * Lifecycle callback to perform cleanup.
// */
// void destroy();
//
// /**
// * get value from memcached
// */
// Object get(CacheNamespace cacheNamespace, String key);
//
// /**
// * set value to memcache with expirySeconds
// */
// void set(CacheNamespace cacheNamespace, String key, Object value, int expirySeconds);
//
// /**
// * delete key from memcached
// */
// void delete(CacheNamespace cacheNamespace, String key);
//
// /**
// * increase given increment couter and return new value.
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param by the amount of increment
// * @param defaultValue default value when the key missing
// * @return increased value
// */
// long increaseCounter(CacheNamespace cacheNamespace, String key, long by, long defaultValue, int expirySeconds);
//
// /**
// * get current value from increment counter
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param defaultValue default value when the key missing
// * @return current value of counter without increment
// */
// long getCounter(CacheNamespace cacheNamespace, String key, long defaultValue, int expirySeconds);
//
// /**
// * Evict namespace
// *
// * @param cacheNamespace cache namespace
// */
// void evictAll(CacheNamespace cacheNamespace);
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/util/OverridableReadOnlyProperties.java
// public interface OverridableReadOnlyProperties {
// String getProperty(String key);
//
// String getProperty(String key, String defaultValue);
//
// String getRequiredProperty(String key);
// }
| import kr.pe.kwonnam.hibernate4memcached.memcached.CacheNamespace;
import kr.pe.kwonnam.hibernate4memcached.memcached.MemcachedAdapter;
import kr.pe.kwonnam.hibernate4memcached.util.OverridableReadOnlyProperties; | package kr.pe.kwonnam.hibernate4memcached;
/**
* @author KwonNam Son ([email protected])
*/
public class FakeMemcachedAdapter implements MemcachedAdapter {
boolean initCalled = false;
public boolean isInitCalled() {
return initCalled;
}
@Override
public void init(OverridableReadOnlyProperties properties) {
initCalled = true;
}
@Override
public void destroy() {
}
@Override | // Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/memcached/CacheNamespace.java
// public class CacheNamespace implements Serializable {
// /**
// * name of region
// */
// private String name;
//
// /**
// * if this value is true, the memcached adapter should implement namespace pattern
// * or ignore namespace pattern.
// * <p/>
// * see <a href="https://code.google.com/p/memcached/wiki/NewProgrammingTricks#Namespacing">Memcached Namespacing</a>
// */
// private boolean namespaceExpirationRequired;
//
// public CacheNamespace(String name, boolean namespaceExpirationRequired) {
// this.name = name;
// this.namespaceExpirationRequired = namespaceExpirationRequired;
// }
//
// public String getName() {
// return name;
// }
//
// public boolean isNamespaceExpirationRequired() {
// return namespaceExpirationRequired;
// }
//
// @Override
// public boolean equals(Object o) {
// if (o == null) {
// return false;
// }
// if (this == o) {
// return true;
// }
// if (getClass() != o.getClass()) {
// return false;
// }
//
// CacheNamespace otherCacheNamespace = (CacheNamespace) o;
//
// return new EqualsBuilder().append(name, otherCacheNamespace.name)
// .append(namespaceExpirationRequired, otherCacheNamespace.namespaceExpirationRequired).isEquals();
// }
//
// @Override
// public int hashCode() {
// return new HashCodeBuilder().append(name).append(namespaceExpirationRequired).toHashCode();
// }
//
// @Override
// public String toString() {
// return new ToStringBuilder(this).append("name", name).append("namespaceExpirationRequired", namespaceExpirationRequired).toString();
// }
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/memcached/MemcachedAdapter.java
// public interface MemcachedAdapter {
// /**
// * Lifecycle callback to perform initialization.
// *
// * @param properties the defined cfg properties
// */
// void init(OverridableReadOnlyProperties properties);
//
// /**
// * Lifecycle callback to perform cleanup.
// */
// void destroy();
//
// /**
// * get value from memcached
// */
// Object get(CacheNamespace cacheNamespace, String key);
//
// /**
// * set value to memcache with expirySeconds
// */
// void set(CacheNamespace cacheNamespace, String key, Object value, int expirySeconds);
//
// /**
// * delete key from memcached
// */
// void delete(CacheNamespace cacheNamespace, String key);
//
// /**
// * increase given increment couter and return new value.
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param by the amount of increment
// * @param defaultValue default value when the key missing
// * @return increased value
// */
// long increaseCounter(CacheNamespace cacheNamespace, String key, long by, long defaultValue, int expirySeconds);
//
// /**
// * get current value from increment counter
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param defaultValue default value when the key missing
// * @return current value of counter without increment
// */
// long getCounter(CacheNamespace cacheNamespace, String key, long defaultValue, int expirySeconds);
//
// /**
// * Evict namespace
// *
// * @param cacheNamespace cache namespace
// */
// void evictAll(CacheNamespace cacheNamespace);
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/util/OverridableReadOnlyProperties.java
// public interface OverridableReadOnlyProperties {
// String getProperty(String key);
//
// String getProperty(String key, String defaultValue);
//
// String getRequiredProperty(String key);
// }
// Path: hibernate4-memcached-core/src/test/java/kr/pe/kwonnam/hibernate4memcached/FakeMemcachedAdapter.java
import kr.pe.kwonnam.hibernate4memcached.memcached.CacheNamespace;
import kr.pe.kwonnam.hibernate4memcached.memcached.MemcachedAdapter;
import kr.pe.kwonnam.hibernate4memcached.util.OverridableReadOnlyProperties;
package kr.pe.kwonnam.hibernate4memcached;
/**
* @author KwonNam Son ([email protected])
*/
public class FakeMemcachedAdapter implements MemcachedAdapter {
boolean initCalled = false;
public boolean isInitCalled() {
return initCalled;
}
@Override
public void init(OverridableReadOnlyProperties properties) {
initCalled = true;
}
@Override
public void destroy() {
}
@Override | public Object get(CacheNamespace cacheNamespace, String key) { |
kwon37xi/hibernate4-memcached | hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/regions/MemcachedRegion.java | // Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/memcached/CacheNamespace.java
// public class CacheNamespace implements Serializable {
// /**
// * name of region
// */
// private String name;
//
// /**
// * if this value is true, the memcached adapter should implement namespace pattern
// * or ignore namespace pattern.
// * <p/>
// * see <a href="https://code.google.com/p/memcached/wiki/NewProgrammingTricks#Namespacing">Memcached Namespacing</a>
// */
// private boolean namespaceExpirationRequired;
//
// public CacheNamespace(String name, boolean namespaceExpirationRequired) {
// this.name = name;
// this.namespaceExpirationRequired = namespaceExpirationRequired;
// }
//
// public String getName() {
// return name;
// }
//
// public boolean isNamespaceExpirationRequired() {
// return namespaceExpirationRequired;
// }
//
// @Override
// public boolean equals(Object o) {
// if (o == null) {
// return false;
// }
// if (this == o) {
// return true;
// }
// if (getClass() != o.getClass()) {
// return false;
// }
//
// CacheNamespace otherCacheNamespace = (CacheNamespace) o;
//
// return new EqualsBuilder().append(name, otherCacheNamespace.name)
// .append(namespaceExpirationRequired, otherCacheNamespace.namespaceExpirationRequired).isEquals();
// }
//
// @Override
// public int hashCode() {
// return new HashCodeBuilder().append(name).append(namespaceExpirationRequired).toHashCode();
// }
//
// @Override
// public String toString() {
// return new ToStringBuilder(this).append("name", name).append("namespaceExpirationRequired", namespaceExpirationRequired).toString();
// }
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/memcached/MemcachedAdapter.java
// public interface MemcachedAdapter {
// /**
// * Lifecycle callback to perform initialization.
// *
// * @param properties the defined cfg properties
// */
// void init(OverridableReadOnlyProperties properties);
//
// /**
// * Lifecycle callback to perform cleanup.
// */
// void destroy();
//
// /**
// * get value from memcached
// */
// Object get(CacheNamespace cacheNamespace, String key);
//
// /**
// * set value to memcache with expirySeconds
// */
// void set(CacheNamespace cacheNamespace, String key, Object value, int expirySeconds);
//
// /**
// * delete key from memcached
// */
// void delete(CacheNamespace cacheNamespace, String key);
//
// /**
// * increase given increment couter and return new value.
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param by the amount of increment
// * @param defaultValue default value when the key missing
// * @return increased value
// */
// long increaseCounter(CacheNamespace cacheNamespace, String key, long by, long defaultValue, int expirySeconds);
//
// /**
// * get current value from increment counter
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param defaultValue default value when the key missing
// * @return current value of counter without increment
// */
// long getCounter(CacheNamespace cacheNamespace, String key, long defaultValue, int expirySeconds);
//
// /**
// * Evict namespace
// *
// * @param cacheNamespace cache namespace
// */
// void evictAll(CacheNamespace cacheNamespace);
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/timestamper/HibernateCacheTimestamper.java
// public interface HibernateCacheTimestamper {
//
// void setSettings(Settings settings);
//
// void setProperties(OverridableReadOnlyProperties properties);
//
// void setMemcachedAdapter(MemcachedAdapter memcachedAdapter);
//
// /** initialize timestamp object */
// void init();
//
// /** get next timestamp */
// long next();
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/util/OverridableReadOnlyProperties.java
// public interface OverridableReadOnlyProperties {
// String getProperty(String key);
//
// String getProperty(String key, String defaultValue);
//
// String getRequiredProperty(String key);
// }
| import kr.pe.kwonnam.hibernate4memcached.memcached.CacheNamespace;
import kr.pe.kwonnam.hibernate4memcached.memcached.MemcachedAdapter;
import kr.pe.kwonnam.hibernate4memcached.timestamper.HibernateCacheTimestamper;
import kr.pe.kwonnam.hibernate4memcached.util.OverridableReadOnlyProperties;
import org.hibernate.cache.CacheException;
import org.hibernate.cache.spi.CacheDataDescription;
import org.hibernate.cache.spi.Region;
import org.hibernate.cfg.Settings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Map; | package kr.pe.kwonnam.hibernate4memcached.regions;
/**
* @author KwonNam Son ([email protected])
*/
public class MemcachedRegion implements Region {
private Logger log = LoggerFactory.getLogger(MemcachedRegion.class);
public static final int UNKNOWN = -1;
private static final int DEFAULT_CACHE_LOCK_TIMEOUT_MILLIS = 60 * 1000;
| // Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/memcached/CacheNamespace.java
// public class CacheNamespace implements Serializable {
// /**
// * name of region
// */
// private String name;
//
// /**
// * if this value is true, the memcached adapter should implement namespace pattern
// * or ignore namespace pattern.
// * <p/>
// * see <a href="https://code.google.com/p/memcached/wiki/NewProgrammingTricks#Namespacing">Memcached Namespacing</a>
// */
// private boolean namespaceExpirationRequired;
//
// public CacheNamespace(String name, boolean namespaceExpirationRequired) {
// this.name = name;
// this.namespaceExpirationRequired = namespaceExpirationRequired;
// }
//
// public String getName() {
// return name;
// }
//
// public boolean isNamespaceExpirationRequired() {
// return namespaceExpirationRequired;
// }
//
// @Override
// public boolean equals(Object o) {
// if (o == null) {
// return false;
// }
// if (this == o) {
// return true;
// }
// if (getClass() != o.getClass()) {
// return false;
// }
//
// CacheNamespace otherCacheNamespace = (CacheNamespace) o;
//
// return new EqualsBuilder().append(name, otherCacheNamespace.name)
// .append(namespaceExpirationRequired, otherCacheNamespace.namespaceExpirationRequired).isEquals();
// }
//
// @Override
// public int hashCode() {
// return new HashCodeBuilder().append(name).append(namespaceExpirationRequired).toHashCode();
// }
//
// @Override
// public String toString() {
// return new ToStringBuilder(this).append("name", name).append("namespaceExpirationRequired", namespaceExpirationRequired).toString();
// }
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/memcached/MemcachedAdapter.java
// public interface MemcachedAdapter {
// /**
// * Lifecycle callback to perform initialization.
// *
// * @param properties the defined cfg properties
// */
// void init(OverridableReadOnlyProperties properties);
//
// /**
// * Lifecycle callback to perform cleanup.
// */
// void destroy();
//
// /**
// * get value from memcached
// */
// Object get(CacheNamespace cacheNamespace, String key);
//
// /**
// * set value to memcache with expirySeconds
// */
// void set(CacheNamespace cacheNamespace, String key, Object value, int expirySeconds);
//
// /**
// * delete key from memcached
// */
// void delete(CacheNamespace cacheNamespace, String key);
//
// /**
// * increase given increment couter and return new value.
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param by the amount of increment
// * @param defaultValue default value when the key missing
// * @return increased value
// */
// long increaseCounter(CacheNamespace cacheNamespace, String key, long by, long defaultValue, int expirySeconds);
//
// /**
// * get current value from increment counter
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param defaultValue default value when the key missing
// * @return current value of counter without increment
// */
// long getCounter(CacheNamespace cacheNamespace, String key, long defaultValue, int expirySeconds);
//
// /**
// * Evict namespace
// *
// * @param cacheNamespace cache namespace
// */
// void evictAll(CacheNamespace cacheNamespace);
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/timestamper/HibernateCacheTimestamper.java
// public interface HibernateCacheTimestamper {
//
// void setSettings(Settings settings);
//
// void setProperties(OverridableReadOnlyProperties properties);
//
// void setMemcachedAdapter(MemcachedAdapter memcachedAdapter);
//
// /** initialize timestamp object */
// void init();
//
// /** get next timestamp */
// long next();
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/util/OverridableReadOnlyProperties.java
// public interface OverridableReadOnlyProperties {
// String getProperty(String key);
//
// String getProperty(String key, String defaultValue);
//
// String getRequiredProperty(String key);
// }
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/regions/MemcachedRegion.java
import kr.pe.kwonnam.hibernate4memcached.memcached.CacheNamespace;
import kr.pe.kwonnam.hibernate4memcached.memcached.MemcachedAdapter;
import kr.pe.kwonnam.hibernate4memcached.timestamper.HibernateCacheTimestamper;
import kr.pe.kwonnam.hibernate4memcached.util.OverridableReadOnlyProperties;
import org.hibernate.cache.CacheException;
import org.hibernate.cache.spi.CacheDataDescription;
import org.hibernate.cache.spi.Region;
import org.hibernate.cfg.Settings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Map;
package kr.pe.kwonnam.hibernate4memcached.regions;
/**
* @author KwonNam Son ([email protected])
*/
public class MemcachedRegion implements Region {
private Logger log = LoggerFactory.getLogger(MemcachedRegion.class);
public static final int UNKNOWN = -1;
private static final int DEFAULT_CACHE_LOCK_TIMEOUT_MILLIS = 60 * 1000;
| private CacheNamespace cacheNamespace; |
kwon37xi/hibernate4-memcached | hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/regions/MemcachedRegion.java | // Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/memcached/CacheNamespace.java
// public class CacheNamespace implements Serializable {
// /**
// * name of region
// */
// private String name;
//
// /**
// * if this value is true, the memcached adapter should implement namespace pattern
// * or ignore namespace pattern.
// * <p/>
// * see <a href="https://code.google.com/p/memcached/wiki/NewProgrammingTricks#Namespacing">Memcached Namespacing</a>
// */
// private boolean namespaceExpirationRequired;
//
// public CacheNamespace(String name, boolean namespaceExpirationRequired) {
// this.name = name;
// this.namespaceExpirationRequired = namespaceExpirationRequired;
// }
//
// public String getName() {
// return name;
// }
//
// public boolean isNamespaceExpirationRequired() {
// return namespaceExpirationRequired;
// }
//
// @Override
// public boolean equals(Object o) {
// if (o == null) {
// return false;
// }
// if (this == o) {
// return true;
// }
// if (getClass() != o.getClass()) {
// return false;
// }
//
// CacheNamespace otherCacheNamespace = (CacheNamespace) o;
//
// return new EqualsBuilder().append(name, otherCacheNamespace.name)
// .append(namespaceExpirationRequired, otherCacheNamespace.namespaceExpirationRequired).isEquals();
// }
//
// @Override
// public int hashCode() {
// return new HashCodeBuilder().append(name).append(namespaceExpirationRequired).toHashCode();
// }
//
// @Override
// public String toString() {
// return new ToStringBuilder(this).append("name", name).append("namespaceExpirationRequired", namespaceExpirationRequired).toString();
// }
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/memcached/MemcachedAdapter.java
// public interface MemcachedAdapter {
// /**
// * Lifecycle callback to perform initialization.
// *
// * @param properties the defined cfg properties
// */
// void init(OverridableReadOnlyProperties properties);
//
// /**
// * Lifecycle callback to perform cleanup.
// */
// void destroy();
//
// /**
// * get value from memcached
// */
// Object get(CacheNamespace cacheNamespace, String key);
//
// /**
// * set value to memcache with expirySeconds
// */
// void set(CacheNamespace cacheNamespace, String key, Object value, int expirySeconds);
//
// /**
// * delete key from memcached
// */
// void delete(CacheNamespace cacheNamespace, String key);
//
// /**
// * increase given increment couter and return new value.
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param by the amount of increment
// * @param defaultValue default value when the key missing
// * @return increased value
// */
// long increaseCounter(CacheNamespace cacheNamespace, String key, long by, long defaultValue, int expirySeconds);
//
// /**
// * get current value from increment counter
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param defaultValue default value when the key missing
// * @return current value of counter without increment
// */
// long getCounter(CacheNamespace cacheNamespace, String key, long defaultValue, int expirySeconds);
//
// /**
// * Evict namespace
// *
// * @param cacheNamespace cache namespace
// */
// void evictAll(CacheNamespace cacheNamespace);
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/timestamper/HibernateCacheTimestamper.java
// public interface HibernateCacheTimestamper {
//
// void setSettings(Settings settings);
//
// void setProperties(OverridableReadOnlyProperties properties);
//
// void setMemcachedAdapter(MemcachedAdapter memcachedAdapter);
//
// /** initialize timestamp object */
// void init();
//
// /** get next timestamp */
// long next();
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/util/OverridableReadOnlyProperties.java
// public interface OverridableReadOnlyProperties {
// String getProperty(String key);
//
// String getProperty(String key, String defaultValue);
//
// String getRequiredProperty(String key);
// }
| import kr.pe.kwonnam.hibernate4memcached.memcached.CacheNamespace;
import kr.pe.kwonnam.hibernate4memcached.memcached.MemcachedAdapter;
import kr.pe.kwonnam.hibernate4memcached.timestamper.HibernateCacheTimestamper;
import kr.pe.kwonnam.hibernate4memcached.util.OverridableReadOnlyProperties;
import org.hibernate.cache.CacheException;
import org.hibernate.cache.spi.CacheDataDescription;
import org.hibernate.cache.spi.Region;
import org.hibernate.cfg.Settings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Map; | package kr.pe.kwonnam.hibernate4memcached.regions;
/**
* @author KwonNam Son ([email protected])
*/
public class MemcachedRegion implements Region {
private Logger log = LoggerFactory.getLogger(MemcachedRegion.class);
public static final int UNKNOWN = -1;
private static final int DEFAULT_CACHE_LOCK_TIMEOUT_MILLIS = 60 * 1000;
private CacheNamespace cacheNamespace;
| // Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/memcached/CacheNamespace.java
// public class CacheNamespace implements Serializable {
// /**
// * name of region
// */
// private String name;
//
// /**
// * if this value is true, the memcached adapter should implement namespace pattern
// * or ignore namespace pattern.
// * <p/>
// * see <a href="https://code.google.com/p/memcached/wiki/NewProgrammingTricks#Namespacing">Memcached Namespacing</a>
// */
// private boolean namespaceExpirationRequired;
//
// public CacheNamespace(String name, boolean namespaceExpirationRequired) {
// this.name = name;
// this.namespaceExpirationRequired = namespaceExpirationRequired;
// }
//
// public String getName() {
// return name;
// }
//
// public boolean isNamespaceExpirationRequired() {
// return namespaceExpirationRequired;
// }
//
// @Override
// public boolean equals(Object o) {
// if (o == null) {
// return false;
// }
// if (this == o) {
// return true;
// }
// if (getClass() != o.getClass()) {
// return false;
// }
//
// CacheNamespace otherCacheNamespace = (CacheNamespace) o;
//
// return new EqualsBuilder().append(name, otherCacheNamespace.name)
// .append(namespaceExpirationRequired, otherCacheNamespace.namespaceExpirationRequired).isEquals();
// }
//
// @Override
// public int hashCode() {
// return new HashCodeBuilder().append(name).append(namespaceExpirationRequired).toHashCode();
// }
//
// @Override
// public String toString() {
// return new ToStringBuilder(this).append("name", name).append("namespaceExpirationRequired", namespaceExpirationRequired).toString();
// }
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/memcached/MemcachedAdapter.java
// public interface MemcachedAdapter {
// /**
// * Lifecycle callback to perform initialization.
// *
// * @param properties the defined cfg properties
// */
// void init(OverridableReadOnlyProperties properties);
//
// /**
// * Lifecycle callback to perform cleanup.
// */
// void destroy();
//
// /**
// * get value from memcached
// */
// Object get(CacheNamespace cacheNamespace, String key);
//
// /**
// * set value to memcache with expirySeconds
// */
// void set(CacheNamespace cacheNamespace, String key, Object value, int expirySeconds);
//
// /**
// * delete key from memcached
// */
// void delete(CacheNamespace cacheNamespace, String key);
//
// /**
// * increase given increment couter and return new value.
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param by the amount of increment
// * @param defaultValue default value when the key missing
// * @return increased value
// */
// long increaseCounter(CacheNamespace cacheNamespace, String key, long by, long defaultValue, int expirySeconds);
//
// /**
// * get current value from increment counter
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param defaultValue default value when the key missing
// * @return current value of counter without increment
// */
// long getCounter(CacheNamespace cacheNamespace, String key, long defaultValue, int expirySeconds);
//
// /**
// * Evict namespace
// *
// * @param cacheNamespace cache namespace
// */
// void evictAll(CacheNamespace cacheNamespace);
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/timestamper/HibernateCacheTimestamper.java
// public interface HibernateCacheTimestamper {
//
// void setSettings(Settings settings);
//
// void setProperties(OverridableReadOnlyProperties properties);
//
// void setMemcachedAdapter(MemcachedAdapter memcachedAdapter);
//
// /** initialize timestamp object */
// void init();
//
// /** get next timestamp */
// long next();
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/util/OverridableReadOnlyProperties.java
// public interface OverridableReadOnlyProperties {
// String getProperty(String key);
//
// String getProperty(String key, String defaultValue);
//
// String getRequiredProperty(String key);
// }
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/regions/MemcachedRegion.java
import kr.pe.kwonnam.hibernate4memcached.memcached.CacheNamespace;
import kr.pe.kwonnam.hibernate4memcached.memcached.MemcachedAdapter;
import kr.pe.kwonnam.hibernate4memcached.timestamper.HibernateCacheTimestamper;
import kr.pe.kwonnam.hibernate4memcached.util.OverridableReadOnlyProperties;
import org.hibernate.cache.CacheException;
import org.hibernate.cache.spi.CacheDataDescription;
import org.hibernate.cache.spi.Region;
import org.hibernate.cfg.Settings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Map;
package kr.pe.kwonnam.hibernate4memcached.regions;
/**
* @author KwonNam Son ([email protected])
*/
public class MemcachedRegion implements Region {
private Logger log = LoggerFactory.getLogger(MemcachedRegion.class);
public static final int UNKNOWN = -1;
private static final int DEFAULT_CACHE_LOCK_TIMEOUT_MILLIS = 60 * 1000;
private CacheNamespace cacheNamespace;
| private OverridableReadOnlyProperties properties; |
kwon37xi/hibernate4-memcached | hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/regions/MemcachedRegion.java | // Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/memcached/CacheNamespace.java
// public class CacheNamespace implements Serializable {
// /**
// * name of region
// */
// private String name;
//
// /**
// * if this value is true, the memcached adapter should implement namespace pattern
// * or ignore namespace pattern.
// * <p/>
// * see <a href="https://code.google.com/p/memcached/wiki/NewProgrammingTricks#Namespacing">Memcached Namespacing</a>
// */
// private boolean namespaceExpirationRequired;
//
// public CacheNamespace(String name, boolean namespaceExpirationRequired) {
// this.name = name;
// this.namespaceExpirationRequired = namespaceExpirationRequired;
// }
//
// public String getName() {
// return name;
// }
//
// public boolean isNamespaceExpirationRequired() {
// return namespaceExpirationRequired;
// }
//
// @Override
// public boolean equals(Object o) {
// if (o == null) {
// return false;
// }
// if (this == o) {
// return true;
// }
// if (getClass() != o.getClass()) {
// return false;
// }
//
// CacheNamespace otherCacheNamespace = (CacheNamespace) o;
//
// return new EqualsBuilder().append(name, otherCacheNamespace.name)
// .append(namespaceExpirationRequired, otherCacheNamespace.namespaceExpirationRequired).isEquals();
// }
//
// @Override
// public int hashCode() {
// return new HashCodeBuilder().append(name).append(namespaceExpirationRequired).toHashCode();
// }
//
// @Override
// public String toString() {
// return new ToStringBuilder(this).append("name", name).append("namespaceExpirationRequired", namespaceExpirationRequired).toString();
// }
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/memcached/MemcachedAdapter.java
// public interface MemcachedAdapter {
// /**
// * Lifecycle callback to perform initialization.
// *
// * @param properties the defined cfg properties
// */
// void init(OverridableReadOnlyProperties properties);
//
// /**
// * Lifecycle callback to perform cleanup.
// */
// void destroy();
//
// /**
// * get value from memcached
// */
// Object get(CacheNamespace cacheNamespace, String key);
//
// /**
// * set value to memcache with expirySeconds
// */
// void set(CacheNamespace cacheNamespace, String key, Object value, int expirySeconds);
//
// /**
// * delete key from memcached
// */
// void delete(CacheNamespace cacheNamespace, String key);
//
// /**
// * increase given increment couter and return new value.
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param by the amount of increment
// * @param defaultValue default value when the key missing
// * @return increased value
// */
// long increaseCounter(CacheNamespace cacheNamespace, String key, long by, long defaultValue, int expirySeconds);
//
// /**
// * get current value from increment counter
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param defaultValue default value when the key missing
// * @return current value of counter without increment
// */
// long getCounter(CacheNamespace cacheNamespace, String key, long defaultValue, int expirySeconds);
//
// /**
// * Evict namespace
// *
// * @param cacheNamespace cache namespace
// */
// void evictAll(CacheNamespace cacheNamespace);
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/timestamper/HibernateCacheTimestamper.java
// public interface HibernateCacheTimestamper {
//
// void setSettings(Settings settings);
//
// void setProperties(OverridableReadOnlyProperties properties);
//
// void setMemcachedAdapter(MemcachedAdapter memcachedAdapter);
//
// /** initialize timestamp object */
// void init();
//
// /** get next timestamp */
// long next();
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/util/OverridableReadOnlyProperties.java
// public interface OverridableReadOnlyProperties {
// String getProperty(String key);
//
// String getProperty(String key, String defaultValue);
//
// String getRequiredProperty(String key);
// }
| import kr.pe.kwonnam.hibernate4memcached.memcached.CacheNamespace;
import kr.pe.kwonnam.hibernate4memcached.memcached.MemcachedAdapter;
import kr.pe.kwonnam.hibernate4memcached.timestamper.HibernateCacheTimestamper;
import kr.pe.kwonnam.hibernate4memcached.util.OverridableReadOnlyProperties;
import org.hibernate.cache.CacheException;
import org.hibernate.cache.spi.CacheDataDescription;
import org.hibernate.cache.spi.Region;
import org.hibernate.cfg.Settings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Map; | package kr.pe.kwonnam.hibernate4memcached.regions;
/**
* @author KwonNam Son ([email protected])
*/
public class MemcachedRegion implements Region {
private Logger log = LoggerFactory.getLogger(MemcachedRegion.class);
public static final int UNKNOWN = -1;
private static final int DEFAULT_CACHE_LOCK_TIMEOUT_MILLIS = 60 * 1000;
private CacheNamespace cacheNamespace;
private OverridableReadOnlyProperties properties;
private CacheDataDescription metadata;
private Settings settings;
| // Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/memcached/CacheNamespace.java
// public class CacheNamespace implements Serializable {
// /**
// * name of region
// */
// private String name;
//
// /**
// * if this value is true, the memcached adapter should implement namespace pattern
// * or ignore namespace pattern.
// * <p/>
// * see <a href="https://code.google.com/p/memcached/wiki/NewProgrammingTricks#Namespacing">Memcached Namespacing</a>
// */
// private boolean namespaceExpirationRequired;
//
// public CacheNamespace(String name, boolean namespaceExpirationRequired) {
// this.name = name;
// this.namespaceExpirationRequired = namespaceExpirationRequired;
// }
//
// public String getName() {
// return name;
// }
//
// public boolean isNamespaceExpirationRequired() {
// return namespaceExpirationRequired;
// }
//
// @Override
// public boolean equals(Object o) {
// if (o == null) {
// return false;
// }
// if (this == o) {
// return true;
// }
// if (getClass() != o.getClass()) {
// return false;
// }
//
// CacheNamespace otherCacheNamespace = (CacheNamespace) o;
//
// return new EqualsBuilder().append(name, otherCacheNamespace.name)
// .append(namespaceExpirationRequired, otherCacheNamespace.namespaceExpirationRequired).isEquals();
// }
//
// @Override
// public int hashCode() {
// return new HashCodeBuilder().append(name).append(namespaceExpirationRequired).toHashCode();
// }
//
// @Override
// public String toString() {
// return new ToStringBuilder(this).append("name", name).append("namespaceExpirationRequired", namespaceExpirationRequired).toString();
// }
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/memcached/MemcachedAdapter.java
// public interface MemcachedAdapter {
// /**
// * Lifecycle callback to perform initialization.
// *
// * @param properties the defined cfg properties
// */
// void init(OverridableReadOnlyProperties properties);
//
// /**
// * Lifecycle callback to perform cleanup.
// */
// void destroy();
//
// /**
// * get value from memcached
// */
// Object get(CacheNamespace cacheNamespace, String key);
//
// /**
// * set value to memcache with expirySeconds
// */
// void set(CacheNamespace cacheNamespace, String key, Object value, int expirySeconds);
//
// /**
// * delete key from memcached
// */
// void delete(CacheNamespace cacheNamespace, String key);
//
// /**
// * increase given increment couter and return new value.
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param by the amount of increment
// * @param defaultValue default value when the key missing
// * @return increased value
// */
// long increaseCounter(CacheNamespace cacheNamespace, String key, long by, long defaultValue, int expirySeconds);
//
// /**
// * get current value from increment counter
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param defaultValue default value when the key missing
// * @return current value of counter without increment
// */
// long getCounter(CacheNamespace cacheNamespace, String key, long defaultValue, int expirySeconds);
//
// /**
// * Evict namespace
// *
// * @param cacheNamespace cache namespace
// */
// void evictAll(CacheNamespace cacheNamespace);
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/timestamper/HibernateCacheTimestamper.java
// public interface HibernateCacheTimestamper {
//
// void setSettings(Settings settings);
//
// void setProperties(OverridableReadOnlyProperties properties);
//
// void setMemcachedAdapter(MemcachedAdapter memcachedAdapter);
//
// /** initialize timestamp object */
// void init();
//
// /** get next timestamp */
// long next();
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/util/OverridableReadOnlyProperties.java
// public interface OverridableReadOnlyProperties {
// String getProperty(String key);
//
// String getProperty(String key, String defaultValue);
//
// String getRequiredProperty(String key);
// }
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/regions/MemcachedRegion.java
import kr.pe.kwonnam.hibernate4memcached.memcached.CacheNamespace;
import kr.pe.kwonnam.hibernate4memcached.memcached.MemcachedAdapter;
import kr.pe.kwonnam.hibernate4memcached.timestamper.HibernateCacheTimestamper;
import kr.pe.kwonnam.hibernate4memcached.util.OverridableReadOnlyProperties;
import org.hibernate.cache.CacheException;
import org.hibernate.cache.spi.CacheDataDescription;
import org.hibernate.cache.spi.Region;
import org.hibernate.cfg.Settings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Map;
package kr.pe.kwonnam.hibernate4memcached.regions;
/**
* @author KwonNam Son ([email protected])
*/
public class MemcachedRegion implements Region {
private Logger log = LoggerFactory.getLogger(MemcachedRegion.class);
public static final int UNKNOWN = -1;
private static final int DEFAULT_CACHE_LOCK_TIMEOUT_MILLIS = 60 * 1000;
private CacheNamespace cacheNamespace;
private OverridableReadOnlyProperties properties;
private CacheDataDescription metadata;
private Settings settings;
| private MemcachedAdapter memcachedAdapter; |
kwon37xi/hibernate4-memcached | hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/regions/MemcachedRegion.java | // Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/memcached/CacheNamespace.java
// public class CacheNamespace implements Serializable {
// /**
// * name of region
// */
// private String name;
//
// /**
// * if this value is true, the memcached adapter should implement namespace pattern
// * or ignore namespace pattern.
// * <p/>
// * see <a href="https://code.google.com/p/memcached/wiki/NewProgrammingTricks#Namespacing">Memcached Namespacing</a>
// */
// private boolean namespaceExpirationRequired;
//
// public CacheNamespace(String name, boolean namespaceExpirationRequired) {
// this.name = name;
// this.namespaceExpirationRequired = namespaceExpirationRequired;
// }
//
// public String getName() {
// return name;
// }
//
// public boolean isNamespaceExpirationRequired() {
// return namespaceExpirationRequired;
// }
//
// @Override
// public boolean equals(Object o) {
// if (o == null) {
// return false;
// }
// if (this == o) {
// return true;
// }
// if (getClass() != o.getClass()) {
// return false;
// }
//
// CacheNamespace otherCacheNamespace = (CacheNamespace) o;
//
// return new EqualsBuilder().append(name, otherCacheNamespace.name)
// .append(namespaceExpirationRequired, otherCacheNamespace.namespaceExpirationRequired).isEquals();
// }
//
// @Override
// public int hashCode() {
// return new HashCodeBuilder().append(name).append(namespaceExpirationRequired).toHashCode();
// }
//
// @Override
// public String toString() {
// return new ToStringBuilder(this).append("name", name).append("namespaceExpirationRequired", namespaceExpirationRequired).toString();
// }
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/memcached/MemcachedAdapter.java
// public interface MemcachedAdapter {
// /**
// * Lifecycle callback to perform initialization.
// *
// * @param properties the defined cfg properties
// */
// void init(OverridableReadOnlyProperties properties);
//
// /**
// * Lifecycle callback to perform cleanup.
// */
// void destroy();
//
// /**
// * get value from memcached
// */
// Object get(CacheNamespace cacheNamespace, String key);
//
// /**
// * set value to memcache with expirySeconds
// */
// void set(CacheNamespace cacheNamespace, String key, Object value, int expirySeconds);
//
// /**
// * delete key from memcached
// */
// void delete(CacheNamespace cacheNamespace, String key);
//
// /**
// * increase given increment couter and return new value.
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param by the amount of increment
// * @param defaultValue default value when the key missing
// * @return increased value
// */
// long increaseCounter(CacheNamespace cacheNamespace, String key, long by, long defaultValue, int expirySeconds);
//
// /**
// * get current value from increment counter
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param defaultValue default value when the key missing
// * @return current value of counter without increment
// */
// long getCounter(CacheNamespace cacheNamespace, String key, long defaultValue, int expirySeconds);
//
// /**
// * Evict namespace
// *
// * @param cacheNamespace cache namespace
// */
// void evictAll(CacheNamespace cacheNamespace);
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/timestamper/HibernateCacheTimestamper.java
// public interface HibernateCacheTimestamper {
//
// void setSettings(Settings settings);
//
// void setProperties(OverridableReadOnlyProperties properties);
//
// void setMemcachedAdapter(MemcachedAdapter memcachedAdapter);
//
// /** initialize timestamp object */
// void init();
//
// /** get next timestamp */
// long next();
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/util/OverridableReadOnlyProperties.java
// public interface OverridableReadOnlyProperties {
// String getProperty(String key);
//
// String getProperty(String key, String defaultValue);
//
// String getRequiredProperty(String key);
// }
| import kr.pe.kwonnam.hibernate4memcached.memcached.CacheNamespace;
import kr.pe.kwonnam.hibernate4memcached.memcached.MemcachedAdapter;
import kr.pe.kwonnam.hibernate4memcached.timestamper.HibernateCacheTimestamper;
import kr.pe.kwonnam.hibernate4memcached.util.OverridableReadOnlyProperties;
import org.hibernate.cache.CacheException;
import org.hibernate.cache.spi.CacheDataDescription;
import org.hibernate.cache.spi.Region;
import org.hibernate.cfg.Settings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Map; | package kr.pe.kwonnam.hibernate4memcached.regions;
/**
* @author KwonNam Son ([email protected])
*/
public class MemcachedRegion implements Region {
private Logger log = LoggerFactory.getLogger(MemcachedRegion.class);
public static final int UNKNOWN = -1;
private static final int DEFAULT_CACHE_LOCK_TIMEOUT_MILLIS = 60 * 1000;
private CacheNamespace cacheNamespace;
private OverridableReadOnlyProperties properties;
private CacheDataDescription metadata;
private Settings settings;
private MemcachedAdapter memcachedAdapter;
| // Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/memcached/CacheNamespace.java
// public class CacheNamespace implements Serializable {
// /**
// * name of region
// */
// private String name;
//
// /**
// * if this value is true, the memcached adapter should implement namespace pattern
// * or ignore namespace pattern.
// * <p/>
// * see <a href="https://code.google.com/p/memcached/wiki/NewProgrammingTricks#Namespacing">Memcached Namespacing</a>
// */
// private boolean namespaceExpirationRequired;
//
// public CacheNamespace(String name, boolean namespaceExpirationRequired) {
// this.name = name;
// this.namespaceExpirationRequired = namespaceExpirationRequired;
// }
//
// public String getName() {
// return name;
// }
//
// public boolean isNamespaceExpirationRequired() {
// return namespaceExpirationRequired;
// }
//
// @Override
// public boolean equals(Object o) {
// if (o == null) {
// return false;
// }
// if (this == o) {
// return true;
// }
// if (getClass() != o.getClass()) {
// return false;
// }
//
// CacheNamespace otherCacheNamespace = (CacheNamespace) o;
//
// return new EqualsBuilder().append(name, otherCacheNamespace.name)
// .append(namespaceExpirationRequired, otherCacheNamespace.namespaceExpirationRequired).isEquals();
// }
//
// @Override
// public int hashCode() {
// return new HashCodeBuilder().append(name).append(namespaceExpirationRequired).toHashCode();
// }
//
// @Override
// public String toString() {
// return new ToStringBuilder(this).append("name", name).append("namespaceExpirationRequired", namespaceExpirationRequired).toString();
// }
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/memcached/MemcachedAdapter.java
// public interface MemcachedAdapter {
// /**
// * Lifecycle callback to perform initialization.
// *
// * @param properties the defined cfg properties
// */
// void init(OverridableReadOnlyProperties properties);
//
// /**
// * Lifecycle callback to perform cleanup.
// */
// void destroy();
//
// /**
// * get value from memcached
// */
// Object get(CacheNamespace cacheNamespace, String key);
//
// /**
// * set value to memcache with expirySeconds
// */
// void set(CacheNamespace cacheNamespace, String key, Object value, int expirySeconds);
//
// /**
// * delete key from memcached
// */
// void delete(CacheNamespace cacheNamespace, String key);
//
// /**
// * increase given increment couter and return new value.
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param by the amount of increment
// * @param defaultValue default value when the key missing
// * @return increased value
// */
// long increaseCounter(CacheNamespace cacheNamespace, String key, long by, long defaultValue, int expirySeconds);
//
// /**
// * get current value from increment counter
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param defaultValue default value when the key missing
// * @return current value of counter without increment
// */
// long getCounter(CacheNamespace cacheNamespace, String key, long defaultValue, int expirySeconds);
//
// /**
// * Evict namespace
// *
// * @param cacheNamespace cache namespace
// */
// void evictAll(CacheNamespace cacheNamespace);
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/timestamper/HibernateCacheTimestamper.java
// public interface HibernateCacheTimestamper {
//
// void setSettings(Settings settings);
//
// void setProperties(OverridableReadOnlyProperties properties);
//
// void setMemcachedAdapter(MemcachedAdapter memcachedAdapter);
//
// /** initialize timestamp object */
// void init();
//
// /** get next timestamp */
// long next();
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/util/OverridableReadOnlyProperties.java
// public interface OverridableReadOnlyProperties {
// String getProperty(String key);
//
// String getProperty(String key, String defaultValue);
//
// String getRequiredProperty(String key);
// }
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/regions/MemcachedRegion.java
import kr.pe.kwonnam.hibernate4memcached.memcached.CacheNamespace;
import kr.pe.kwonnam.hibernate4memcached.memcached.MemcachedAdapter;
import kr.pe.kwonnam.hibernate4memcached.timestamper.HibernateCacheTimestamper;
import kr.pe.kwonnam.hibernate4memcached.util.OverridableReadOnlyProperties;
import org.hibernate.cache.CacheException;
import org.hibernate.cache.spi.CacheDataDescription;
import org.hibernate.cache.spi.Region;
import org.hibernate.cfg.Settings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Map;
package kr.pe.kwonnam.hibernate4memcached.regions;
/**
* @author KwonNam Son ([email protected])
*/
public class MemcachedRegion implements Region {
private Logger log = LoggerFactory.getLogger(MemcachedRegion.class);
public static final int UNKNOWN = -1;
private static final int DEFAULT_CACHE_LOCK_TIMEOUT_MILLIS = 60 * 1000;
private CacheNamespace cacheNamespace;
private OverridableReadOnlyProperties properties;
private CacheDataDescription metadata;
private Settings settings;
private MemcachedAdapter memcachedAdapter;
| private HibernateCacheTimestamper hibernateCacheTimestamper; |
kwon37xi/hibernate4-memcached | hibernate4-memcached-core/src/test/java/kr/pe/kwonnam/hibernate4memcached/regions/CollectionMemcachedRegionTest.java | // Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/strategies/NonstrictReadWriteCollectionRegionAccessStrategy.java
// public class NonstrictReadWriteCollectionRegionAccessStrategy extends BaseCollectionMemcachedRegionAccessStrategy {
// public NonstrictReadWriteCollectionRegionAccessStrategy(CollectionMemcachedRegion collectionMemcachedRegion) {
// super(collectionMemcachedRegion);
// }
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/strategies/ReadOnlyCollectionRegionAccessStrategy.java
// public class ReadOnlyCollectionRegionAccessStrategy extends BaseCollectionMemcachedRegionAccessStrategy {
// public ReadOnlyCollectionRegionAccessStrategy(CollectionMemcachedRegion collectionMemcachedRegion) {
// super(collectionMemcachedRegion);
// }
// }
| import kr.pe.kwonnam.hibernate4memcached.strategies.NonstrictReadWriteCollectionRegionAccessStrategy;
import kr.pe.kwonnam.hibernate4memcached.strategies.ReadOnlyCollectionRegionAccessStrategy;
import org.hibernate.cache.CacheException;
import org.hibernate.cache.spi.access.AccessType;
import org.junit.Test;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.hamcrest.CoreMatchers.containsString; | package kr.pe.kwonnam.hibernate4memcached.regions;
public class CollectionMemcachedRegionTest extends AbstractFinalMemcachedRegionTest {
private CollectionMemcachedRegion collectionMemcachedRegion;
@Override
protected void afterSetUp() throws Exception {
collectionMemcachedRegion = new CollectionMemcachedRegion("books.authors", properties, metadata, settings, memcachedAdapter, hibernateCacheTimestamper);
}
@Test
public void buildAccessStrategy_AccessType_READ_ONLY() throws Exception {
assertThat(collectionMemcachedRegion.buildAccessStrategy(AccessType.READ_ONLY)) | // Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/strategies/NonstrictReadWriteCollectionRegionAccessStrategy.java
// public class NonstrictReadWriteCollectionRegionAccessStrategy extends BaseCollectionMemcachedRegionAccessStrategy {
// public NonstrictReadWriteCollectionRegionAccessStrategy(CollectionMemcachedRegion collectionMemcachedRegion) {
// super(collectionMemcachedRegion);
// }
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/strategies/ReadOnlyCollectionRegionAccessStrategy.java
// public class ReadOnlyCollectionRegionAccessStrategy extends BaseCollectionMemcachedRegionAccessStrategy {
// public ReadOnlyCollectionRegionAccessStrategy(CollectionMemcachedRegion collectionMemcachedRegion) {
// super(collectionMemcachedRegion);
// }
// }
// Path: hibernate4-memcached-core/src/test/java/kr/pe/kwonnam/hibernate4memcached/regions/CollectionMemcachedRegionTest.java
import kr.pe.kwonnam.hibernate4memcached.strategies.NonstrictReadWriteCollectionRegionAccessStrategy;
import kr.pe.kwonnam.hibernate4memcached.strategies.ReadOnlyCollectionRegionAccessStrategy;
import org.hibernate.cache.CacheException;
import org.hibernate.cache.spi.access.AccessType;
import org.junit.Test;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.hamcrest.CoreMatchers.containsString;
package kr.pe.kwonnam.hibernate4memcached.regions;
public class CollectionMemcachedRegionTest extends AbstractFinalMemcachedRegionTest {
private CollectionMemcachedRegion collectionMemcachedRegion;
@Override
protected void afterSetUp() throws Exception {
collectionMemcachedRegion = new CollectionMemcachedRegion("books.authors", properties, metadata, settings, memcachedAdapter, hibernateCacheTimestamper);
}
@Test
public void buildAccessStrategy_AccessType_READ_ONLY() throws Exception {
assertThat(collectionMemcachedRegion.buildAccessStrategy(AccessType.READ_ONLY)) | .isExactlyInstanceOf(ReadOnlyCollectionRegionAccessStrategy.class); |
kwon37xi/hibernate4-memcached | hibernate4-memcached-core/src/test/java/kr/pe/kwonnam/hibernate4memcached/regions/CollectionMemcachedRegionTest.java | // Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/strategies/NonstrictReadWriteCollectionRegionAccessStrategy.java
// public class NonstrictReadWriteCollectionRegionAccessStrategy extends BaseCollectionMemcachedRegionAccessStrategy {
// public NonstrictReadWriteCollectionRegionAccessStrategy(CollectionMemcachedRegion collectionMemcachedRegion) {
// super(collectionMemcachedRegion);
// }
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/strategies/ReadOnlyCollectionRegionAccessStrategy.java
// public class ReadOnlyCollectionRegionAccessStrategy extends BaseCollectionMemcachedRegionAccessStrategy {
// public ReadOnlyCollectionRegionAccessStrategy(CollectionMemcachedRegion collectionMemcachedRegion) {
// super(collectionMemcachedRegion);
// }
// }
| import kr.pe.kwonnam.hibernate4memcached.strategies.NonstrictReadWriteCollectionRegionAccessStrategy;
import kr.pe.kwonnam.hibernate4memcached.strategies.ReadOnlyCollectionRegionAccessStrategy;
import org.hibernate.cache.CacheException;
import org.hibernate.cache.spi.access.AccessType;
import org.junit.Test;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.hamcrest.CoreMatchers.containsString; | package kr.pe.kwonnam.hibernate4memcached.regions;
public class CollectionMemcachedRegionTest extends AbstractFinalMemcachedRegionTest {
private CollectionMemcachedRegion collectionMemcachedRegion;
@Override
protected void afterSetUp() throws Exception {
collectionMemcachedRegion = new CollectionMemcachedRegion("books.authors", properties, metadata, settings, memcachedAdapter, hibernateCacheTimestamper);
}
@Test
public void buildAccessStrategy_AccessType_READ_ONLY() throws Exception {
assertThat(collectionMemcachedRegion.buildAccessStrategy(AccessType.READ_ONLY))
.isExactlyInstanceOf(ReadOnlyCollectionRegionAccessStrategy.class);
}
@Test
public void buildAccessStrategy_AccessType_NONSTRICT_READ_WRITE() throws Exception {
assertThat(collectionMemcachedRegion.buildAccessStrategy(AccessType.NONSTRICT_READ_WRITE)) | // Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/strategies/NonstrictReadWriteCollectionRegionAccessStrategy.java
// public class NonstrictReadWriteCollectionRegionAccessStrategy extends BaseCollectionMemcachedRegionAccessStrategy {
// public NonstrictReadWriteCollectionRegionAccessStrategy(CollectionMemcachedRegion collectionMemcachedRegion) {
// super(collectionMemcachedRegion);
// }
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/strategies/ReadOnlyCollectionRegionAccessStrategy.java
// public class ReadOnlyCollectionRegionAccessStrategy extends BaseCollectionMemcachedRegionAccessStrategy {
// public ReadOnlyCollectionRegionAccessStrategy(CollectionMemcachedRegion collectionMemcachedRegion) {
// super(collectionMemcachedRegion);
// }
// }
// Path: hibernate4-memcached-core/src/test/java/kr/pe/kwonnam/hibernate4memcached/regions/CollectionMemcachedRegionTest.java
import kr.pe.kwonnam.hibernate4memcached.strategies.NonstrictReadWriteCollectionRegionAccessStrategy;
import kr.pe.kwonnam.hibernate4memcached.strategies.ReadOnlyCollectionRegionAccessStrategy;
import org.hibernate.cache.CacheException;
import org.hibernate.cache.spi.access.AccessType;
import org.junit.Test;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.hamcrest.CoreMatchers.containsString;
package kr.pe.kwonnam.hibernate4memcached.regions;
public class CollectionMemcachedRegionTest extends AbstractFinalMemcachedRegionTest {
private CollectionMemcachedRegion collectionMemcachedRegion;
@Override
protected void afterSetUp() throws Exception {
collectionMemcachedRegion = new CollectionMemcachedRegion("books.authors", properties, metadata, settings, memcachedAdapter, hibernateCacheTimestamper);
}
@Test
public void buildAccessStrategy_AccessType_READ_ONLY() throws Exception {
assertThat(collectionMemcachedRegion.buildAccessStrategy(AccessType.READ_ONLY))
.isExactlyInstanceOf(ReadOnlyCollectionRegionAccessStrategy.class);
}
@Test
public void buildAccessStrategy_AccessType_NONSTRICT_READ_WRITE() throws Exception {
assertThat(collectionMemcachedRegion.buildAccessStrategy(AccessType.NONSTRICT_READ_WRITE)) | .isExactlyInstanceOf(NonstrictReadWriteCollectionRegionAccessStrategy.class); |
kwon37xi/hibernate4-memcached | hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/strategies/NonstrictReadWriteEntityRegionAccessStrategy.java | // Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/regions/EntityMemcachedRegion.java
// public class EntityMemcachedRegion extends TransactionalDataMemcachedRegion implements EntityRegion {
// public EntityMemcachedRegion(String regionName, OverridableReadOnlyProperties properties, CacheDataDescription metadata, Settings settings, MemcachedAdapter memcachedAdapter, HibernateCacheTimestamper hibernateCacheTimestamper) {
// super(new CacheNamespace(regionName, true), properties, metadata, settings, memcachedAdapter, hibernateCacheTimestamper);
// }
//
// @Override
// public EntityRegionAccessStrategy buildAccessStrategy(AccessType accessType) throws CacheException {
// switch (accessType) {
// case READ_ONLY:
// return new ReadOnlyEntityRegionAccessStrategy(this);
// case NONSTRICT_READ_WRITE:
// return new NonstrictReadWriteEntityRegionAccessStrategy(this);
// default:
// throw new CacheException("Unsupported access strategy : " + accessType + ".");
// }
// }
// }
| import kr.pe.kwonnam.hibernate4memcached.regions.EntityMemcachedRegion;
import org.hibernate.cache.CacheException;
import org.hibernate.cache.spi.access.SoftLock;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory; | package kr.pe.kwonnam.hibernate4memcached.strategies;
/**
* @author KwonNam Son ([email protected])
*/
public class NonstrictReadWriteEntityRegionAccessStrategy extends BaseEntityMemcachedRegionAccessStrategy {
private Logger log = LoggerFactory.getLogger(NonstrictReadWriteEntityRegionAccessStrategy.class);
| // Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/regions/EntityMemcachedRegion.java
// public class EntityMemcachedRegion extends TransactionalDataMemcachedRegion implements EntityRegion {
// public EntityMemcachedRegion(String regionName, OverridableReadOnlyProperties properties, CacheDataDescription metadata, Settings settings, MemcachedAdapter memcachedAdapter, HibernateCacheTimestamper hibernateCacheTimestamper) {
// super(new CacheNamespace(regionName, true), properties, metadata, settings, memcachedAdapter, hibernateCacheTimestamper);
// }
//
// @Override
// public EntityRegionAccessStrategy buildAccessStrategy(AccessType accessType) throws CacheException {
// switch (accessType) {
// case READ_ONLY:
// return new ReadOnlyEntityRegionAccessStrategy(this);
// case NONSTRICT_READ_WRITE:
// return new NonstrictReadWriteEntityRegionAccessStrategy(this);
// default:
// throw new CacheException("Unsupported access strategy : " + accessType + ".");
// }
// }
// }
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/strategies/NonstrictReadWriteEntityRegionAccessStrategy.java
import kr.pe.kwonnam.hibernate4memcached.regions.EntityMemcachedRegion;
import org.hibernate.cache.CacheException;
import org.hibernate.cache.spi.access.SoftLock;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
package kr.pe.kwonnam.hibernate4memcached.strategies;
/**
* @author KwonNam Son ([email protected])
*/
public class NonstrictReadWriteEntityRegionAccessStrategy extends BaseEntityMemcachedRegionAccessStrategy {
private Logger log = LoggerFactory.getLogger(NonstrictReadWriteEntityRegionAccessStrategy.class);
| public NonstrictReadWriteEntityRegionAccessStrategy(EntityMemcachedRegion entityMemcachedRegion) { |
kwon37xi/hibernate4-memcached | hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/strategies/MemcachedRegionAccessStrategy.java | // Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/regions/GeneralDataMemcachedRegion.java
// public class GeneralDataMemcachedRegion extends MemcachedRegion implements GeneralDataRegion {
// private Logger log = LoggerFactory.getLogger(GeneralDataMemcachedRegion.class);
//
// private int expirySeconds;
//
// public GeneralDataMemcachedRegion(CacheNamespace cacheNamespace, OverridableReadOnlyProperties properties, CacheDataDescription metadata,
// Settings settings, MemcachedAdapter memcachedAdapter, HibernateCacheTimestamper hibernateCacheTimestamper) {
// super(cacheNamespace, properties, metadata, settings, memcachedAdapter, hibernateCacheTimestamper);
// populateExpirySeconds(properties);
// }
//
// void populateExpirySeconds(OverridableReadOnlyProperties properties) {
// String regionExpirySecondsKey = REGION_EXPIRY_SECONDS_PROPERTY_KEY_PREFIX + "." + getCacheNamespace().getName();
// String expirySecondsProperty = properties.getProperty(regionExpirySecondsKey);
// if (expirySecondsProperty == null) {
// expirySecondsProperty = properties.getProperty(REGION_EXPIRY_SECONDS_PROPERTY_KEY_PREFIX);
// }
// if (expirySecondsProperty == null) {
// throw new IllegalStateException(regionExpirySecondsKey + " or " + REGION_EXPIRY_SECONDS_PROPERTY_KEY_PREFIX
// + "(for default expiry seconds) required!");
// }
//
// expirySeconds = Integer.parseInt(expirySecondsProperty);
// log.info("expirySeconds of cache region [{}] - {} seconds.", getCacheNamespace().getName(), expirySeconds);
// }
//
// @Override
// public Object get(Object key) throws CacheException {
// String refinedKey = refineKey(key);
//
// log.debug("Cache get [{}] : key[{}]", getCacheNamespace(), refinedKey);
//
// Object cachedData;
// try {
// cachedData = getMemcachedAdapter().get(getCacheNamespace(), refinedKey);
// } catch (Exception ex) {
// log.warn("Failed to get from memcached.", ex);
// cachedData = null;
// }
//
// if (cachedData == null) {
// return null;
// }
//
// if (!(cachedData instanceof CacheItem)) {
// log.debug("get cachedData is not CacheItem.");
// return cachedData;
// }
//
// CacheItem cacheItem = (CacheItem) cachedData;
// boolean targetClassAndCurrentJvmTargetClassMatch = cacheItem.isTargetClassAndCurrentJvmTargetClassMatch();
// log.debug("cacheItem and targetClassAndCurrentJvmTargetClassMatch : {} / {}", targetClassAndCurrentJvmTargetClassMatch, cacheItem);
//
// if (cacheItem.isTargetClassAndCurrentJvmTargetClassMatch()) {
// return cacheItem.getCacheEntry();
// }
//
// return null;
// }
//
// @Override
// public void put(Object key, Object value) throws CacheException {
//
// Object valueToCache = value;
//
// boolean classVersionApplicable = CacheItem.checkIfClassVersionApplicable(value, getSettings().isStructuredCacheEntriesEnabled());
//
// if (classVersionApplicable) {
// valueToCache = new CacheItem(value, getSettings().isStructuredCacheEntriesEnabled());
// }
//
// String refinedKey = refineKey(key);
// log.debug("Cache put [{}] : key[{}], value[{}], classVersionApplicable : {}", getCacheNamespace(), refinedKey,
// valueToCache, classVersionApplicable);
// try {
// getMemcachedAdapter().set(getCacheNamespace(), refinedKey, valueToCache, getExpiryInSeconds());
// } catch (Exception ex) {
// log.warn("Failed to set memcached value.", ex);
// }
// }
//
// @Override
// public void evict(Object key) throws CacheException {
// String refinedKey = refineKey(key);
// log.debug("Cache evict[{}] : key[{}]", getCacheNamespace(), refinedKey);
// try {
// getMemcachedAdapter().delete(getCacheNamespace(), refinedKey);
// } catch (Exception ex) {
// log.warn("Failed to delete memcached value.", ex);
// }
// }
//
// @Override
// public void evictAll() throws CacheException {
// log.debug("Cache evictAll [{}].", getCacheNamespace());
// try {
// getMemcachedAdapter().evictAll(getCacheNamespace());
// } catch (Exception ex) {
// log.warn("Failed to evictAll.", ex);
// }
// }
//
// /**
// * Read expiry seconds from configuration properties
// */
// protected int getExpiryInSeconds() {
// return expirySeconds;
// }
//
// /**
// * Memcached has limitation of key size. Shorten the key to avoid the limitation if needed.
// */
// protected String refineKey(Object key) {
// return String.valueOf(key);
// }
// }
| import kr.pe.kwonnam.hibernate4memcached.regions.GeneralDataMemcachedRegion;
import org.hibernate.cache.CacheException;
import org.hibernate.cache.spi.access.RegionAccessStrategy;
import org.hibernate.cache.spi.access.SoftLock;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory; | package kr.pe.kwonnam.hibernate4memcached.strategies;
/**
* Basic Memcached Region Access Strategy.
* <p/>
* This strategy is for READ_ONLY and NONSTRICT_READ_WRITE.
* This is not suitable for READ_WRITE and TRANSACTIONAL.
* READ_WRITE, TRANSACTION strategy must override this class's methods.
*
* @author KwonNam Son ([email protected])
*/
public class MemcachedRegionAccessStrategy implements RegionAccessStrategy {
private Logger log = LoggerFactory.getLogger(MemcachedRegionAccessStrategy.class);
| // Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/regions/GeneralDataMemcachedRegion.java
// public class GeneralDataMemcachedRegion extends MemcachedRegion implements GeneralDataRegion {
// private Logger log = LoggerFactory.getLogger(GeneralDataMemcachedRegion.class);
//
// private int expirySeconds;
//
// public GeneralDataMemcachedRegion(CacheNamespace cacheNamespace, OverridableReadOnlyProperties properties, CacheDataDescription metadata,
// Settings settings, MemcachedAdapter memcachedAdapter, HibernateCacheTimestamper hibernateCacheTimestamper) {
// super(cacheNamespace, properties, metadata, settings, memcachedAdapter, hibernateCacheTimestamper);
// populateExpirySeconds(properties);
// }
//
// void populateExpirySeconds(OverridableReadOnlyProperties properties) {
// String regionExpirySecondsKey = REGION_EXPIRY_SECONDS_PROPERTY_KEY_PREFIX + "." + getCacheNamespace().getName();
// String expirySecondsProperty = properties.getProperty(regionExpirySecondsKey);
// if (expirySecondsProperty == null) {
// expirySecondsProperty = properties.getProperty(REGION_EXPIRY_SECONDS_PROPERTY_KEY_PREFIX);
// }
// if (expirySecondsProperty == null) {
// throw new IllegalStateException(regionExpirySecondsKey + " or " + REGION_EXPIRY_SECONDS_PROPERTY_KEY_PREFIX
// + "(for default expiry seconds) required!");
// }
//
// expirySeconds = Integer.parseInt(expirySecondsProperty);
// log.info("expirySeconds of cache region [{}] - {} seconds.", getCacheNamespace().getName(), expirySeconds);
// }
//
// @Override
// public Object get(Object key) throws CacheException {
// String refinedKey = refineKey(key);
//
// log.debug("Cache get [{}] : key[{}]", getCacheNamespace(), refinedKey);
//
// Object cachedData;
// try {
// cachedData = getMemcachedAdapter().get(getCacheNamespace(), refinedKey);
// } catch (Exception ex) {
// log.warn("Failed to get from memcached.", ex);
// cachedData = null;
// }
//
// if (cachedData == null) {
// return null;
// }
//
// if (!(cachedData instanceof CacheItem)) {
// log.debug("get cachedData is not CacheItem.");
// return cachedData;
// }
//
// CacheItem cacheItem = (CacheItem) cachedData;
// boolean targetClassAndCurrentJvmTargetClassMatch = cacheItem.isTargetClassAndCurrentJvmTargetClassMatch();
// log.debug("cacheItem and targetClassAndCurrentJvmTargetClassMatch : {} / {}", targetClassAndCurrentJvmTargetClassMatch, cacheItem);
//
// if (cacheItem.isTargetClassAndCurrentJvmTargetClassMatch()) {
// return cacheItem.getCacheEntry();
// }
//
// return null;
// }
//
// @Override
// public void put(Object key, Object value) throws CacheException {
//
// Object valueToCache = value;
//
// boolean classVersionApplicable = CacheItem.checkIfClassVersionApplicable(value, getSettings().isStructuredCacheEntriesEnabled());
//
// if (classVersionApplicable) {
// valueToCache = new CacheItem(value, getSettings().isStructuredCacheEntriesEnabled());
// }
//
// String refinedKey = refineKey(key);
// log.debug("Cache put [{}] : key[{}], value[{}], classVersionApplicable : {}", getCacheNamespace(), refinedKey,
// valueToCache, classVersionApplicable);
// try {
// getMemcachedAdapter().set(getCacheNamespace(), refinedKey, valueToCache, getExpiryInSeconds());
// } catch (Exception ex) {
// log.warn("Failed to set memcached value.", ex);
// }
// }
//
// @Override
// public void evict(Object key) throws CacheException {
// String refinedKey = refineKey(key);
// log.debug("Cache evict[{}] : key[{}]", getCacheNamespace(), refinedKey);
// try {
// getMemcachedAdapter().delete(getCacheNamespace(), refinedKey);
// } catch (Exception ex) {
// log.warn("Failed to delete memcached value.", ex);
// }
// }
//
// @Override
// public void evictAll() throws CacheException {
// log.debug("Cache evictAll [{}].", getCacheNamespace());
// try {
// getMemcachedAdapter().evictAll(getCacheNamespace());
// } catch (Exception ex) {
// log.warn("Failed to evictAll.", ex);
// }
// }
//
// /**
// * Read expiry seconds from configuration properties
// */
// protected int getExpiryInSeconds() {
// return expirySeconds;
// }
//
// /**
// * Memcached has limitation of key size. Shorten the key to avoid the limitation if needed.
// */
// protected String refineKey(Object key) {
// return String.valueOf(key);
// }
// }
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/strategies/MemcachedRegionAccessStrategy.java
import kr.pe.kwonnam.hibernate4memcached.regions.GeneralDataMemcachedRegion;
import org.hibernate.cache.CacheException;
import org.hibernate.cache.spi.access.RegionAccessStrategy;
import org.hibernate.cache.spi.access.SoftLock;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
package kr.pe.kwonnam.hibernate4memcached.strategies;
/**
* Basic Memcached Region Access Strategy.
* <p/>
* This strategy is for READ_ONLY and NONSTRICT_READ_WRITE.
* This is not suitable for READ_WRITE and TRANSACTIONAL.
* READ_WRITE, TRANSACTION strategy must override this class's methods.
*
* @author KwonNam Son ([email protected])
*/
public class MemcachedRegionAccessStrategy implements RegionAccessStrategy {
private Logger log = LoggerFactory.getLogger(MemcachedRegionAccessStrategy.class);
| private GeneralDataMemcachedRegion internalRegion; |
kwon37xi/hibernate4-memcached | hibernate4-memcached-example/src/test/java/kr/pe/kwonnam/hibernate4memcached/example/QueryCacheTest.java | // Path: hibernate4-memcached-example/src/main/java/kr/pe/kwonnam/hibernate4memcached/example/entity/Author.java
// @Entity
// @Table(name = "authors")
// @org.hibernate.annotations.Cache(region = "authors", usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
// public class Author implements Serializable {
// @Id
// @GeneratedValue(strategy = GenerationType.IDENTITY)
// @Column(name="author_id", nullable = false)
// private long id;
//
// @Column(name = "name", length = 32, nullable = false)
// private String name;
//
// @Column(name = "country", length = 32, nullable = true)
// private String country;
//
// public long getId() {
// return id;
// }
//
// public void setId(long id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public String getCountry() {
// return country;
// }
//
// public void setCountry(String country) {
// this.country = country;
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) return true;
// if (o == null || getClass() != o.getClass()) return false;
//
// Author author = (Author) o;
//
// if (id != author.id) return false;
//
// return true;
// }
//
// @Override
// public int hashCode() {
// return (int) (id ^ (id >>> 32));
// }
//
// @Override
// public String toString() {
// return "Author{" +
// "id=" + id +
// ", name='" + name + '\'' +
// ", country='" + country + '\'' +
// '}';
// }
// }
| import kr.pe.kwonnam.hibernate4memcached.example.entity.Author;
import org.hibernate.Session;
import org.hibernate.ejb.HibernateEntityManagerFactory;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.persistence.Cache;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.TypedQuery;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import java.util.List;
import static org.fest.assertions.api.Assertions.assertThat; | package kr.pe.kwonnam.hibernate4memcached.example;
/**
* Testing Query Cache
*/
public class QueryCacheTest {
private Logger log = LoggerFactory.getLogger(QueryCacheTest.class);
@Before
public void setUp() throws Exception {
EntityTestUtils.init();
}
@After
public void tearDown() throws Exception {
EntityTestUtils.destroy();
}
| // Path: hibernate4-memcached-example/src/main/java/kr/pe/kwonnam/hibernate4memcached/example/entity/Author.java
// @Entity
// @Table(name = "authors")
// @org.hibernate.annotations.Cache(region = "authors", usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
// public class Author implements Serializable {
// @Id
// @GeneratedValue(strategy = GenerationType.IDENTITY)
// @Column(name="author_id", nullable = false)
// private long id;
//
// @Column(name = "name", length = 32, nullable = false)
// private String name;
//
// @Column(name = "country", length = 32, nullable = true)
// private String country;
//
// public long getId() {
// return id;
// }
//
// public void setId(long id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public String getCountry() {
// return country;
// }
//
// public void setCountry(String country) {
// this.country = country;
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) return true;
// if (o == null || getClass() != o.getClass()) return false;
//
// Author author = (Author) o;
//
// if (id != author.id) return false;
//
// return true;
// }
//
// @Override
// public int hashCode() {
// return (int) (id ^ (id >>> 32));
// }
//
// @Override
// public String toString() {
// return "Author{" +
// "id=" + id +
// ", name='" + name + '\'' +
// ", country='" + country + '\'' +
// '}';
// }
// }
// Path: hibernate4-memcached-example/src/test/java/kr/pe/kwonnam/hibernate4memcached/example/QueryCacheTest.java
import kr.pe.kwonnam.hibernate4memcached.example.entity.Author;
import org.hibernate.Session;
import org.hibernate.ejb.HibernateEntityManagerFactory;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.persistence.Cache;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.TypedQuery;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import java.util.List;
import static org.fest.assertions.api.Assertions.assertThat;
package kr.pe.kwonnam.hibernate4memcached.example;
/**
* Testing Query Cache
*/
public class QueryCacheTest {
private Logger log = LoggerFactory.getLogger(QueryCacheTest.class);
@Before
public void setUp() throws Exception {
EntityTestUtils.init();
}
@After
public void tearDown() throws Exception {
EntityTestUtils.destroy();
}
| private List<Author> getAuthorsWithQuery(String logMessage, String country) { |
kwon37xi/hibernate4-memcached | hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/regions/TransactionalDataMemcachedRegion.java | // Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/memcached/CacheNamespace.java
// public class CacheNamespace implements Serializable {
// /**
// * name of region
// */
// private String name;
//
// /**
// * if this value is true, the memcached adapter should implement namespace pattern
// * or ignore namespace pattern.
// * <p/>
// * see <a href="https://code.google.com/p/memcached/wiki/NewProgrammingTricks#Namespacing">Memcached Namespacing</a>
// */
// private boolean namespaceExpirationRequired;
//
// public CacheNamespace(String name, boolean namespaceExpirationRequired) {
// this.name = name;
// this.namespaceExpirationRequired = namespaceExpirationRequired;
// }
//
// public String getName() {
// return name;
// }
//
// public boolean isNamespaceExpirationRequired() {
// return namespaceExpirationRequired;
// }
//
// @Override
// public boolean equals(Object o) {
// if (o == null) {
// return false;
// }
// if (this == o) {
// return true;
// }
// if (getClass() != o.getClass()) {
// return false;
// }
//
// CacheNamespace otherCacheNamespace = (CacheNamespace) o;
//
// return new EqualsBuilder().append(name, otherCacheNamespace.name)
// .append(namespaceExpirationRequired, otherCacheNamespace.namespaceExpirationRequired).isEquals();
// }
//
// @Override
// public int hashCode() {
// return new HashCodeBuilder().append(name).append(namespaceExpirationRequired).toHashCode();
// }
//
// @Override
// public String toString() {
// return new ToStringBuilder(this).append("name", name).append("namespaceExpirationRequired", namespaceExpirationRequired).toString();
// }
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/memcached/MemcachedAdapter.java
// public interface MemcachedAdapter {
// /**
// * Lifecycle callback to perform initialization.
// *
// * @param properties the defined cfg properties
// */
// void init(OverridableReadOnlyProperties properties);
//
// /**
// * Lifecycle callback to perform cleanup.
// */
// void destroy();
//
// /**
// * get value from memcached
// */
// Object get(CacheNamespace cacheNamespace, String key);
//
// /**
// * set value to memcache with expirySeconds
// */
// void set(CacheNamespace cacheNamespace, String key, Object value, int expirySeconds);
//
// /**
// * delete key from memcached
// */
// void delete(CacheNamespace cacheNamespace, String key);
//
// /**
// * increase given increment couter and return new value.
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param by the amount of increment
// * @param defaultValue default value when the key missing
// * @return increased value
// */
// long increaseCounter(CacheNamespace cacheNamespace, String key, long by, long defaultValue, int expirySeconds);
//
// /**
// * get current value from increment counter
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param defaultValue default value when the key missing
// * @return current value of counter without increment
// */
// long getCounter(CacheNamespace cacheNamespace, String key, long defaultValue, int expirySeconds);
//
// /**
// * Evict namespace
// *
// * @param cacheNamespace cache namespace
// */
// void evictAll(CacheNamespace cacheNamespace);
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/timestamper/HibernateCacheTimestamper.java
// public interface HibernateCacheTimestamper {
//
// void setSettings(Settings settings);
//
// void setProperties(OverridableReadOnlyProperties properties);
//
// void setMemcachedAdapter(MemcachedAdapter memcachedAdapter);
//
// /** initialize timestamp object */
// void init();
//
// /** get next timestamp */
// long next();
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/util/OverridableReadOnlyProperties.java
// public interface OverridableReadOnlyProperties {
// String getProperty(String key);
//
// String getProperty(String key, String defaultValue);
//
// String getRequiredProperty(String key);
// }
| import kr.pe.kwonnam.hibernate4memcached.memcached.CacheNamespace;
import kr.pe.kwonnam.hibernate4memcached.memcached.MemcachedAdapter;
import kr.pe.kwonnam.hibernate4memcached.timestamper.HibernateCacheTimestamper;
import kr.pe.kwonnam.hibernate4memcached.util.OverridableReadOnlyProperties;
import org.hibernate.cache.spi.CacheDataDescription;
import org.hibernate.cache.spi.TransactionalDataRegion;
import org.hibernate.cfg.Settings; | package kr.pe.kwonnam.hibernate4memcached.regions;
/**
* @author KwonNam Son ([email protected])
*/
public class TransactionalDataMemcachedRegion extends GeneralDataMemcachedRegion implements TransactionalDataRegion {
public TransactionalDataMemcachedRegion(CacheNamespace cacheNamespace, OverridableReadOnlyProperties properties, CacheDataDescription metadata, Settings settings, | // Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/memcached/CacheNamespace.java
// public class CacheNamespace implements Serializable {
// /**
// * name of region
// */
// private String name;
//
// /**
// * if this value is true, the memcached adapter should implement namespace pattern
// * or ignore namespace pattern.
// * <p/>
// * see <a href="https://code.google.com/p/memcached/wiki/NewProgrammingTricks#Namespacing">Memcached Namespacing</a>
// */
// private boolean namespaceExpirationRequired;
//
// public CacheNamespace(String name, boolean namespaceExpirationRequired) {
// this.name = name;
// this.namespaceExpirationRequired = namespaceExpirationRequired;
// }
//
// public String getName() {
// return name;
// }
//
// public boolean isNamespaceExpirationRequired() {
// return namespaceExpirationRequired;
// }
//
// @Override
// public boolean equals(Object o) {
// if (o == null) {
// return false;
// }
// if (this == o) {
// return true;
// }
// if (getClass() != o.getClass()) {
// return false;
// }
//
// CacheNamespace otherCacheNamespace = (CacheNamespace) o;
//
// return new EqualsBuilder().append(name, otherCacheNamespace.name)
// .append(namespaceExpirationRequired, otherCacheNamespace.namespaceExpirationRequired).isEquals();
// }
//
// @Override
// public int hashCode() {
// return new HashCodeBuilder().append(name).append(namespaceExpirationRequired).toHashCode();
// }
//
// @Override
// public String toString() {
// return new ToStringBuilder(this).append("name", name).append("namespaceExpirationRequired", namespaceExpirationRequired).toString();
// }
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/memcached/MemcachedAdapter.java
// public interface MemcachedAdapter {
// /**
// * Lifecycle callback to perform initialization.
// *
// * @param properties the defined cfg properties
// */
// void init(OverridableReadOnlyProperties properties);
//
// /**
// * Lifecycle callback to perform cleanup.
// */
// void destroy();
//
// /**
// * get value from memcached
// */
// Object get(CacheNamespace cacheNamespace, String key);
//
// /**
// * set value to memcache with expirySeconds
// */
// void set(CacheNamespace cacheNamespace, String key, Object value, int expirySeconds);
//
// /**
// * delete key from memcached
// */
// void delete(CacheNamespace cacheNamespace, String key);
//
// /**
// * increase given increment couter and return new value.
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param by the amount of increment
// * @param defaultValue default value when the key missing
// * @return increased value
// */
// long increaseCounter(CacheNamespace cacheNamespace, String key, long by, long defaultValue, int expirySeconds);
//
// /**
// * get current value from increment counter
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param defaultValue default value when the key missing
// * @return current value of counter without increment
// */
// long getCounter(CacheNamespace cacheNamespace, String key, long defaultValue, int expirySeconds);
//
// /**
// * Evict namespace
// *
// * @param cacheNamespace cache namespace
// */
// void evictAll(CacheNamespace cacheNamespace);
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/timestamper/HibernateCacheTimestamper.java
// public interface HibernateCacheTimestamper {
//
// void setSettings(Settings settings);
//
// void setProperties(OverridableReadOnlyProperties properties);
//
// void setMemcachedAdapter(MemcachedAdapter memcachedAdapter);
//
// /** initialize timestamp object */
// void init();
//
// /** get next timestamp */
// long next();
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/util/OverridableReadOnlyProperties.java
// public interface OverridableReadOnlyProperties {
// String getProperty(String key);
//
// String getProperty(String key, String defaultValue);
//
// String getRequiredProperty(String key);
// }
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/regions/TransactionalDataMemcachedRegion.java
import kr.pe.kwonnam.hibernate4memcached.memcached.CacheNamespace;
import kr.pe.kwonnam.hibernate4memcached.memcached.MemcachedAdapter;
import kr.pe.kwonnam.hibernate4memcached.timestamper.HibernateCacheTimestamper;
import kr.pe.kwonnam.hibernate4memcached.util.OverridableReadOnlyProperties;
import org.hibernate.cache.spi.CacheDataDescription;
import org.hibernate.cache.spi.TransactionalDataRegion;
import org.hibernate.cfg.Settings;
package kr.pe.kwonnam.hibernate4memcached.regions;
/**
* @author KwonNam Son ([email protected])
*/
public class TransactionalDataMemcachedRegion extends GeneralDataMemcachedRegion implements TransactionalDataRegion {
public TransactionalDataMemcachedRegion(CacheNamespace cacheNamespace, OverridableReadOnlyProperties properties, CacheDataDescription metadata, Settings settings, | MemcachedAdapter memcachedAdapter, HibernateCacheTimestamper hibernateCacheTimestamper) { |
kwon37xi/hibernate4-memcached | hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/regions/TransactionalDataMemcachedRegion.java | // Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/memcached/CacheNamespace.java
// public class CacheNamespace implements Serializable {
// /**
// * name of region
// */
// private String name;
//
// /**
// * if this value is true, the memcached adapter should implement namespace pattern
// * or ignore namespace pattern.
// * <p/>
// * see <a href="https://code.google.com/p/memcached/wiki/NewProgrammingTricks#Namespacing">Memcached Namespacing</a>
// */
// private boolean namespaceExpirationRequired;
//
// public CacheNamespace(String name, boolean namespaceExpirationRequired) {
// this.name = name;
// this.namespaceExpirationRequired = namespaceExpirationRequired;
// }
//
// public String getName() {
// return name;
// }
//
// public boolean isNamespaceExpirationRequired() {
// return namespaceExpirationRequired;
// }
//
// @Override
// public boolean equals(Object o) {
// if (o == null) {
// return false;
// }
// if (this == o) {
// return true;
// }
// if (getClass() != o.getClass()) {
// return false;
// }
//
// CacheNamespace otherCacheNamespace = (CacheNamespace) o;
//
// return new EqualsBuilder().append(name, otherCacheNamespace.name)
// .append(namespaceExpirationRequired, otherCacheNamespace.namespaceExpirationRequired).isEquals();
// }
//
// @Override
// public int hashCode() {
// return new HashCodeBuilder().append(name).append(namespaceExpirationRequired).toHashCode();
// }
//
// @Override
// public String toString() {
// return new ToStringBuilder(this).append("name", name).append("namespaceExpirationRequired", namespaceExpirationRequired).toString();
// }
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/memcached/MemcachedAdapter.java
// public interface MemcachedAdapter {
// /**
// * Lifecycle callback to perform initialization.
// *
// * @param properties the defined cfg properties
// */
// void init(OverridableReadOnlyProperties properties);
//
// /**
// * Lifecycle callback to perform cleanup.
// */
// void destroy();
//
// /**
// * get value from memcached
// */
// Object get(CacheNamespace cacheNamespace, String key);
//
// /**
// * set value to memcache with expirySeconds
// */
// void set(CacheNamespace cacheNamespace, String key, Object value, int expirySeconds);
//
// /**
// * delete key from memcached
// */
// void delete(CacheNamespace cacheNamespace, String key);
//
// /**
// * increase given increment couter and return new value.
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param by the amount of increment
// * @param defaultValue default value when the key missing
// * @return increased value
// */
// long increaseCounter(CacheNamespace cacheNamespace, String key, long by, long defaultValue, int expirySeconds);
//
// /**
// * get current value from increment counter
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param defaultValue default value when the key missing
// * @return current value of counter without increment
// */
// long getCounter(CacheNamespace cacheNamespace, String key, long defaultValue, int expirySeconds);
//
// /**
// * Evict namespace
// *
// * @param cacheNamespace cache namespace
// */
// void evictAll(CacheNamespace cacheNamespace);
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/timestamper/HibernateCacheTimestamper.java
// public interface HibernateCacheTimestamper {
//
// void setSettings(Settings settings);
//
// void setProperties(OverridableReadOnlyProperties properties);
//
// void setMemcachedAdapter(MemcachedAdapter memcachedAdapter);
//
// /** initialize timestamp object */
// void init();
//
// /** get next timestamp */
// long next();
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/util/OverridableReadOnlyProperties.java
// public interface OverridableReadOnlyProperties {
// String getProperty(String key);
//
// String getProperty(String key, String defaultValue);
//
// String getRequiredProperty(String key);
// }
| import kr.pe.kwonnam.hibernate4memcached.memcached.CacheNamespace;
import kr.pe.kwonnam.hibernate4memcached.memcached.MemcachedAdapter;
import kr.pe.kwonnam.hibernate4memcached.timestamper.HibernateCacheTimestamper;
import kr.pe.kwonnam.hibernate4memcached.util.OverridableReadOnlyProperties;
import org.hibernate.cache.spi.CacheDataDescription;
import org.hibernate.cache.spi.TransactionalDataRegion;
import org.hibernate.cfg.Settings; | package kr.pe.kwonnam.hibernate4memcached.regions;
/**
* @author KwonNam Son ([email protected])
*/
public class TransactionalDataMemcachedRegion extends GeneralDataMemcachedRegion implements TransactionalDataRegion {
public TransactionalDataMemcachedRegion(CacheNamespace cacheNamespace, OverridableReadOnlyProperties properties, CacheDataDescription metadata, Settings settings, | // Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/memcached/CacheNamespace.java
// public class CacheNamespace implements Serializable {
// /**
// * name of region
// */
// private String name;
//
// /**
// * if this value is true, the memcached adapter should implement namespace pattern
// * or ignore namespace pattern.
// * <p/>
// * see <a href="https://code.google.com/p/memcached/wiki/NewProgrammingTricks#Namespacing">Memcached Namespacing</a>
// */
// private boolean namespaceExpirationRequired;
//
// public CacheNamespace(String name, boolean namespaceExpirationRequired) {
// this.name = name;
// this.namespaceExpirationRequired = namespaceExpirationRequired;
// }
//
// public String getName() {
// return name;
// }
//
// public boolean isNamespaceExpirationRequired() {
// return namespaceExpirationRequired;
// }
//
// @Override
// public boolean equals(Object o) {
// if (o == null) {
// return false;
// }
// if (this == o) {
// return true;
// }
// if (getClass() != o.getClass()) {
// return false;
// }
//
// CacheNamespace otherCacheNamespace = (CacheNamespace) o;
//
// return new EqualsBuilder().append(name, otherCacheNamespace.name)
// .append(namespaceExpirationRequired, otherCacheNamespace.namespaceExpirationRequired).isEquals();
// }
//
// @Override
// public int hashCode() {
// return new HashCodeBuilder().append(name).append(namespaceExpirationRequired).toHashCode();
// }
//
// @Override
// public String toString() {
// return new ToStringBuilder(this).append("name", name).append("namespaceExpirationRequired", namespaceExpirationRequired).toString();
// }
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/memcached/MemcachedAdapter.java
// public interface MemcachedAdapter {
// /**
// * Lifecycle callback to perform initialization.
// *
// * @param properties the defined cfg properties
// */
// void init(OverridableReadOnlyProperties properties);
//
// /**
// * Lifecycle callback to perform cleanup.
// */
// void destroy();
//
// /**
// * get value from memcached
// */
// Object get(CacheNamespace cacheNamespace, String key);
//
// /**
// * set value to memcache with expirySeconds
// */
// void set(CacheNamespace cacheNamespace, String key, Object value, int expirySeconds);
//
// /**
// * delete key from memcached
// */
// void delete(CacheNamespace cacheNamespace, String key);
//
// /**
// * increase given increment couter and return new value.
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param by the amount of increment
// * @param defaultValue default value when the key missing
// * @return increased value
// */
// long increaseCounter(CacheNamespace cacheNamespace, String key, long by, long defaultValue, int expirySeconds);
//
// /**
// * get current value from increment counter
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param defaultValue default value when the key missing
// * @return current value of counter without increment
// */
// long getCounter(CacheNamespace cacheNamespace, String key, long defaultValue, int expirySeconds);
//
// /**
// * Evict namespace
// *
// * @param cacheNamespace cache namespace
// */
// void evictAll(CacheNamespace cacheNamespace);
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/timestamper/HibernateCacheTimestamper.java
// public interface HibernateCacheTimestamper {
//
// void setSettings(Settings settings);
//
// void setProperties(OverridableReadOnlyProperties properties);
//
// void setMemcachedAdapter(MemcachedAdapter memcachedAdapter);
//
// /** initialize timestamp object */
// void init();
//
// /** get next timestamp */
// long next();
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/util/OverridableReadOnlyProperties.java
// public interface OverridableReadOnlyProperties {
// String getProperty(String key);
//
// String getProperty(String key, String defaultValue);
//
// String getRequiredProperty(String key);
// }
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/regions/TransactionalDataMemcachedRegion.java
import kr.pe.kwonnam.hibernate4memcached.memcached.CacheNamespace;
import kr.pe.kwonnam.hibernate4memcached.memcached.MemcachedAdapter;
import kr.pe.kwonnam.hibernate4memcached.timestamper.HibernateCacheTimestamper;
import kr.pe.kwonnam.hibernate4memcached.util.OverridableReadOnlyProperties;
import org.hibernate.cache.spi.CacheDataDescription;
import org.hibernate.cache.spi.TransactionalDataRegion;
import org.hibernate.cfg.Settings;
package kr.pe.kwonnam.hibernate4memcached.regions;
/**
* @author KwonNam Son ([email protected])
*/
public class TransactionalDataMemcachedRegion extends GeneralDataMemcachedRegion implements TransactionalDataRegion {
public TransactionalDataMemcachedRegion(CacheNamespace cacheNamespace, OverridableReadOnlyProperties properties, CacheDataDescription metadata, Settings settings, | MemcachedAdapter memcachedAdapter, HibernateCacheTimestamper hibernateCacheTimestamper) { |
kwon37xi/hibernate4-memcached | hibernate4-memcached-spymemcached-adapter/src/test/java/kr/pe/kwonnam/hibernate4memcached/spymemcached/authdescriptorgenerator/PlainAuthDescriptorGeneratorTest.java | // Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/util/OverridableReadOnlyPropertiesImpl.java
// public class OverridableReadOnlyPropertiesImpl implements OverridableReadOnlyProperties {
//
// private List<Properties> propertieses;
//
// public OverridableReadOnlyPropertiesImpl(Properties... propertieses) {
// this(Arrays.asList(propertieses));
// }
//
// public OverridableReadOnlyPropertiesImpl(List<Properties> propertieses) {
// if (propertieses == null || propertieses.size() == 0) {
// throw new IllegalArgumentException("propertieses can not be null.");
// }
//
// if (propertieses.contains(null)) {
// throw new IllegalArgumentException("propertieses can not contain null properties");
// }
//
// this.propertieses = propertieses;
// }
//
// @Override
// public String getProperty(String key) {
// return getProperty(key, null);
// }
//
// @Override
// public String getProperty(String key, String defaultValue) {
// int size = propertieses.size();
// for (int i = size - 1; i >= 0; i--) {
// Properties properties = propertieses.get(i);
//
// String value = properties.getProperty(key);
// if (value != null) {
// return value;
// }
// }
// return defaultValue;
// }
//
// @Override
// public String getRequiredProperty(String key) {
// String value = getProperty(key);
// if (value == null) {
// throw new IllegalStateException(key + " property is required!");
// }
// return value;
// }
// }
| import kr.pe.kwonnam.hibernate4memcached.util.OverridableReadOnlyPropertiesImpl;
import net.spy.memcached.auth.AuthDescriptor;
import net.spy.memcached.auth.PlainCallbackHandler;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import java.util.Properties;
import static org.fest.assertions.api.Assertions.assertThat; | package kr.pe.kwonnam.hibernate4memcached.spymemcached.authdescriptorgenerator;
public class PlainAuthDescriptorGeneratorTest {
@Rule
public ExpectedException expectedException = ExpectedException.none();
private PlainAuthDescriptorGenerator generator;
@Before
public void setUp() throws Exception {
generator = new PlainAuthDescriptorGenerator();
}
@Test
public void generate_username_missing() throws Exception {
expectedException.expect(IllegalStateException.class);
Properties props = new Properties();
props.setProperty(PlainAuthDescriptorGenerator.PASSWORD_PROPERTY_KEY, "password");
| // Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/util/OverridableReadOnlyPropertiesImpl.java
// public class OverridableReadOnlyPropertiesImpl implements OverridableReadOnlyProperties {
//
// private List<Properties> propertieses;
//
// public OverridableReadOnlyPropertiesImpl(Properties... propertieses) {
// this(Arrays.asList(propertieses));
// }
//
// public OverridableReadOnlyPropertiesImpl(List<Properties> propertieses) {
// if (propertieses == null || propertieses.size() == 0) {
// throw new IllegalArgumentException("propertieses can not be null.");
// }
//
// if (propertieses.contains(null)) {
// throw new IllegalArgumentException("propertieses can not contain null properties");
// }
//
// this.propertieses = propertieses;
// }
//
// @Override
// public String getProperty(String key) {
// return getProperty(key, null);
// }
//
// @Override
// public String getProperty(String key, String defaultValue) {
// int size = propertieses.size();
// for (int i = size - 1; i >= 0; i--) {
// Properties properties = propertieses.get(i);
//
// String value = properties.getProperty(key);
// if (value != null) {
// return value;
// }
// }
// return defaultValue;
// }
//
// @Override
// public String getRequiredProperty(String key) {
// String value = getProperty(key);
// if (value == null) {
// throw new IllegalStateException(key + " property is required!");
// }
// return value;
// }
// }
// Path: hibernate4-memcached-spymemcached-adapter/src/test/java/kr/pe/kwonnam/hibernate4memcached/spymemcached/authdescriptorgenerator/PlainAuthDescriptorGeneratorTest.java
import kr.pe.kwonnam.hibernate4memcached.util.OverridableReadOnlyPropertiesImpl;
import net.spy.memcached.auth.AuthDescriptor;
import net.spy.memcached.auth.PlainCallbackHandler;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import java.util.Properties;
import static org.fest.assertions.api.Assertions.assertThat;
package kr.pe.kwonnam.hibernate4memcached.spymemcached.authdescriptorgenerator;
public class PlainAuthDescriptorGeneratorTest {
@Rule
public ExpectedException expectedException = ExpectedException.none();
private PlainAuthDescriptorGenerator generator;
@Before
public void setUp() throws Exception {
generator = new PlainAuthDescriptorGenerator();
}
@Test
public void generate_username_missing() throws Exception {
expectedException.expect(IllegalStateException.class);
Properties props = new Properties();
props.setProperty(PlainAuthDescriptorGenerator.PASSWORD_PROPERTY_KEY, "password");
| generator.generate(new OverridableReadOnlyPropertiesImpl(props)); |
kwon37xi/hibernate4-memcached | hibernate4-memcached-core/src/test/java/kr/pe/kwonnam/hibernate4memcached/regions/EntityMemcachedRegionTest.java | // Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/strategies/NonstrictReadWriteEntityRegionAccessStrategy.java
// public class NonstrictReadWriteEntityRegionAccessStrategy extends BaseEntityMemcachedRegionAccessStrategy {
// private Logger log = LoggerFactory.getLogger(NonstrictReadWriteEntityRegionAccessStrategy.class);
//
// public NonstrictReadWriteEntityRegionAccessStrategy(EntityMemcachedRegion entityMemcachedRegion) {
// super(entityMemcachedRegion);
// }
//
// @Override
// public boolean insert(Object key, Object value, Object version) throws CacheException {
// log.debug("region access strategy nonstrict-read-write entity insert() {} {}", getInternalRegion().getCacheNamespace(), key);
// // On nonstrict-read-write, Hibernate never calls this method.
// return false;
// }
//
// @Override
// public boolean afterInsert(Object key, Object value, Object version) throws CacheException {
// log.debug("region access strategy nonstrict-read-write entity afterInsert() {} {}", getInternalRegion().getCacheNamespace(), key);
// // On nonstrict-read-write, Hibernate never calls this method.
// return false;
// }
//
// /**
// * not necessary in nostrict-read-write
// *
// * @see org.hibernate.cache.spi.access.EntityRegionAccessStrategy
// */
// @Override
// public boolean update(Object key, Object value, Object currentVersion, Object previousVersion) throws CacheException {
// log.debug("region access strategy nonstrict-read-write entity update() {} {}", getInternalRegion().getCacheNamespace(), key);
// return false;
// }
//
// /**
// * need evict the key, after update.
// *
// * @see org.hibernate.cache.spi.access.EntityRegionAccessStrategy
// */
// @Override
// public boolean afterUpdate(Object key, Object value, Object currentVersion, Object previousVersion, SoftLock lock) throws CacheException {
// log.debug("region access strategy nonstrict-read-write entity afterUpdate() {} {}", getInternalRegion().getCacheNamespace(), key);
// getInternalRegion().evict(key);
// return false;
// }
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/strategies/ReadOnlyEntityRegionAccessStrategy.java
// public class ReadOnlyEntityRegionAccessStrategy extends BaseEntityMemcachedRegionAccessStrategy {
// private Logger log = LoggerFactory.getLogger(ReadOnlyEntityRegionAccessStrategy.class);
//
// public ReadOnlyEntityRegionAccessStrategy(EntityMemcachedRegion entityMemcachedRegion) {
// super(entityMemcachedRegion);
// }
//
// @Override
// public boolean insert(Object key, Object value, Object version) throws CacheException {
// log.debug("region access strategy readonly entity insert() {} {}", getInternalRegion().getCacheNamespace(), key);
// // On read-only, Hibernate never calls this method.
// return false;
// }
//
// @Override
// public boolean afterInsert(Object key, Object value, Object version) throws CacheException {
// log.debug("region access strategy readonly entity afterInsert() {} {}", getInternalRegion().getCacheNamespace(), key);
// // On read-only, Hibernate never calls this method.
// return false;
// }
//
// /**
// * read-onluy does not support update.
// */
// @Override
// public boolean update(Object key, Object value, Object currentVersion, Object previousVersion) throws CacheException {
// log.debug("region access strategy readonly entity update() {} {}", getInternalRegion().getCacheNamespace(), key);
// throw new UnsupportedOperationException("ReadOnly strategy does not support update.");
// }
//
// /**
// * read-only does not support update.
// */
// @Override
// public boolean afterUpdate(Object key, Object value, Object currentVersion, Object previousVersion, SoftLock lock) throws CacheException {
// log.debug("region access strategy readonly entity afterUpdate() {} {}", getInternalRegion().getCacheNamespace(), key);
// throw new UnsupportedOperationException("ReadOnly strategy does not support update.");
// }
// }
| import kr.pe.kwonnam.hibernate4memcached.strategies.NonstrictReadWriteEntityRegionAccessStrategy;
import kr.pe.kwonnam.hibernate4memcached.strategies.ReadOnlyEntityRegionAccessStrategy;
import org.hibernate.cache.CacheException;
import org.hibernate.cache.spi.access.AccessType;
import org.junit.Test;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.hamcrest.CoreMatchers.containsString; | package kr.pe.kwonnam.hibernate4memcached.regions;
public class EntityMemcachedRegionTest extends AbstractFinalMemcachedRegionTest {
private EntityMemcachedRegion entityMemcachedRegion;
@Override
protected void afterSetUp() throws Exception {
entityMemcachedRegion = new EntityMemcachedRegion("Books", properties, metadata, settings, memcachedAdapter, hibernateCacheTimestamper);
}
@Test
public void buildAccessStrategy_AccessType_READ_ONLY() throws Exception {
assertThat(entityMemcachedRegion.buildAccessStrategy(AccessType.READ_ONLY)) | // Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/strategies/NonstrictReadWriteEntityRegionAccessStrategy.java
// public class NonstrictReadWriteEntityRegionAccessStrategy extends BaseEntityMemcachedRegionAccessStrategy {
// private Logger log = LoggerFactory.getLogger(NonstrictReadWriteEntityRegionAccessStrategy.class);
//
// public NonstrictReadWriteEntityRegionAccessStrategy(EntityMemcachedRegion entityMemcachedRegion) {
// super(entityMemcachedRegion);
// }
//
// @Override
// public boolean insert(Object key, Object value, Object version) throws CacheException {
// log.debug("region access strategy nonstrict-read-write entity insert() {} {}", getInternalRegion().getCacheNamespace(), key);
// // On nonstrict-read-write, Hibernate never calls this method.
// return false;
// }
//
// @Override
// public boolean afterInsert(Object key, Object value, Object version) throws CacheException {
// log.debug("region access strategy nonstrict-read-write entity afterInsert() {} {}", getInternalRegion().getCacheNamespace(), key);
// // On nonstrict-read-write, Hibernate never calls this method.
// return false;
// }
//
// /**
// * not necessary in nostrict-read-write
// *
// * @see org.hibernate.cache.spi.access.EntityRegionAccessStrategy
// */
// @Override
// public boolean update(Object key, Object value, Object currentVersion, Object previousVersion) throws CacheException {
// log.debug("region access strategy nonstrict-read-write entity update() {} {}", getInternalRegion().getCacheNamespace(), key);
// return false;
// }
//
// /**
// * need evict the key, after update.
// *
// * @see org.hibernate.cache.spi.access.EntityRegionAccessStrategy
// */
// @Override
// public boolean afterUpdate(Object key, Object value, Object currentVersion, Object previousVersion, SoftLock lock) throws CacheException {
// log.debug("region access strategy nonstrict-read-write entity afterUpdate() {} {}", getInternalRegion().getCacheNamespace(), key);
// getInternalRegion().evict(key);
// return false;
// }
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/strategies/ReadOnlyEntityRegionAccessStrategy.java
// public class ReadOnlyEntityRegionAccessStrategy extends BaseEntityMemcachedRegionAccessStrategy {
// private Logger log = LoggerFactory.getLogger(ReadOnlyEntityRegionAccessStrategy.class);
//
// public ReadOnlyEntityRegionAccessStrategy(EntityMemcachedRegion entityMemcachedRegion) {
// super(entityMemcachedRegion);
// }
//
// @Override
// public boolean insert(Object key, Object value, Object version) throws CacheException {
// log.debug("region access strategy readonly entity insert() {} {}", getInternalRegion().getCacheNamespace(), key);
// // On read-only, Hibernate never calls this method.
// return false;
// }
//
// @Override
// public boolean afterInsert(Object key, Object value, Object version) throws CacheException {
// log.debug("region access strategy readonly entity afterInsert() {} {}", getInternalRegion().getCacheNamespace(), key);
// // On read-only, Hibernate never calls this method.
// return false;
// }
//
// /**
// * read-onluy does not support update.
// */
// @Override
// public boolean update(Object key, Object value, Object currentVersion, Object previousVersion) throws CacheException {
// log.debug("region access strategy readonly entity update() {} {}", getInternalRegion().getCacheNamespace(), key);
// throw new UnsupportedOperationException("ReadOnly strategy does not support update.");
// }
//
// /**
// * read-only does not support update.
// */
// @Override
// public boolean afterUpdate(Object key, Object value, Object currentVersion, Object previousVersion, SoftLock lock) throws CacheException {
// log.debug("region access strategy readonly entity afterUpdate() {} {}", getInternalRegion().getCacheNamespace(), key);
// throw new UnsupportedOperationException("ReadOnly strategy does not support update.");
// }
// }
// Path: hibernate4-memcached-core/src/test/java/kr/pe/kwonnam/hibernate4memcached/regions/EntityMemcachedRegionTest.java
import kr.pe.kwonnam.hibernate4memcached.strategies.NonstrictReadWriteEntityRegionAccessStrategy;
import kr.pe.kwonnam.hibernate4memcached.strategies.ReadOnlyEntityRegionAccessStrategy;
import org.hibernate.cache.CacheException;
import org.hibernate.cache.spi.access.AccessType;
import org.junit.Test;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.hamcrest.CoreMatchers.containsString;
package kr.pe.kwonnam.hibernate4memcached.regions;
public class EntityMemcachedRegionTest extends AbstractFinalMemcachedRegionTest {
private EntityMemcachedRegion entityMemcachedRegion;
@Override
protected void afterSetUp() throws Exception {
entityMemcachedRegion = new EntityMemcachedRegion("Books", properties, metadata, settings, memcachedAdapter, hibernateCacheTimestamper);
}
@Test
public void buildAccessStrategy_AccessType_READ_ONLY() throws Exception {
assertThat(entityMemcachedRegion.buildAccessStrategy(AccessType.READ_ONLY)) | .isExactlyInstanceOf(ReadOnlyEntityRegionAccessStrategy.class); |
kwon37xi/hibernate4-memcached | hibernate4-memcached-core/src/test/java/kr/pe/kwonnam/hibernate4memcached/regions/EntityMemcachedRegionTest.java | // Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/strategies/NonstrictReadWriteEntityRegionAccessStrategy.java
// public class NonstrictReadWriteEntityRegionAccessStrategy extends BaseEntityMemcachedRegionAccessStrategy {
// private Logger log = LoggerFactory.getLogger(NonstrictReadWriteEntityRegionAccessStrategy.class);
//
// public NonstrictReadWriteEntityRegionAccessStrategy(EntityMemcachedRegion entityMemcachedRegion) {
// super(entityMemcachedRegion);
// }
//
// @Override
// public boolean insert(Object key, Object value, Object version) throws CacheException {
// log.debug("region access strategy nonstrict-read-write entity insert() {} {}", getInternalRegion().getCacheNamespace(), key);
// // On nonstrict-read-write, Hibernate never calls this method.
// return false;
// }
//
// @Override
// public boolean afterInsert(Object key, Object value, Object version) throws CacheException {
// log.debug("region access strategy nonstrict-read-write entity afterInsert() {} {}", getInternalRegion().getCacheNamespace(), key);
// // On nonstrict-read-write, Hibernate never calls this method.
// return false;
// }
//
// /**
// * not necessary in nostrict-read-write
// *
// * @see org.hibernate.cache.spi.access.EntityRegionAccessStrategy
// */
// @Override
// public boolean update(Object key, Object value, Object currentVersion, Object previousVersion) throws CacheException {
// log.debug("region access strategy nonstrict-read-write entity update() {} {}", getInternalRegion().getCacheNamespace(), key);
// return false;
// }
//
// /**
// * need evict the key, after update.
// *
// * @see org.hibernate.cache.spi.access.EntityRegionAccessStrategy
// */
// @Override
// public boolean afterUpdate(Object key, Object value, Object currentVersion, Object previousVersion, SoftLock lock) throws CacheException {
// log.debug("region access strategy nonstrict-read-write entity afterUpdate() {} {}", getInternalRegion().getCacheNamespace(), key);
// getInternalRegion().evict(key);
// return false;
// }
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/strategies/ReadOnlyEntityRegionAccessStrategy.java
// public class ReadOnlyEntityRegionAccessStrategy extends BaseEntityMemcachedRegionAccessStrategy {
// private Logger log = LoggerFactory.getLogger(ReadOnlyEntityRegionAccessStrategy.class);
//
// public ReadOnlyEntityRegionAccessStrategy(EntityMemcachedRegion entityMemcachedRegion) {
// super(entityMemcachedRegion);
// }
//
// @Override
// public boolean insert(Object key, Object value, Object version) throws CacheException {
// log.debug("region access strategy readonly entity insert() {} {}", getInternalRegion().getCacheNamespace(), key);
// // On read-only, Hibernate never calls this method.
// return false;
// }
//
// @Override
// public boolean afterInsert(Object key, Object value, Object version) throws CacheException {
// log.debug("region access strategy readonly entity afterInsert() {} {}", getInternalRegion().getCacheNamespace(), key);
// // On read-only, Hibernate never calls this method.
// return false;
// }
//
// /**
// * read-onluy does not support update.
// */
// @Override
// public boolean update(Object key, Object value, Object currentVersion, Object previousVersion) throws CacheException {
// log.debug("region access strategy readonly entity update() {} {}", getInternalRegion().getCacheNamespace(), key);
// throw new UnsupportedOperationException("ReadOnly strategy does not support update.");
// }
//
// /**
// * read-only does not support update.
// */
// @Override
// public boolean afterUpdate(Object key, Object value, Object currentVersion, Object previousVersion, SoftLock lock) throws CacheException {
// log.debug("region access strategy readonly entity afterUpdate() {} {}", getInternalRegion().getCacheNamespace(), key);
// throw new UnsupportedOperationException("ReadOnly strategy does not support update.");
// }
// }
| import kr.pe.kwonnam.hibernate4memcached.strategies.NonstrictReadWriteEntityRegionAccessStrategy;
import kr.pe.kwonnam.hibernate4memcached.strategies.ReadOnlyEntityRegionAccessStrategy;
import org.hibernate.cache.CacheException;
import org.hibernate.cache.spi.access.AccessType;
import org.junit.Test;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.hamcrest.CoreMatchers.containsString; | package kr.pe.kwonnam.hibernate4memcached.regions;
public class EntityMemcachedRegionTest extends AbstractFinalMemcachedRegionTest {
private EntityMemcachedRegion entityMemcachedRegion;
@Override
protected void afterSetUp() throws Exception {
entityMemcachedRegion = new EntityMemcachedRegion("Books", properties, metadata, settings, memcachedAdapter, hibernateCacheTimestamper);
}
@Test
public void buildAccessStrategy_AccessType_READ_ONLY() throws Exception {
assertThat(entityMemcachedRegion.buildAccessStrategy(AccessType.READ_ONLY))
.isExactlyInstanceOf(ReadOnlyEntityRegionAccessStrategy.class);
}
@Test
public void buildAccessStrategy_AccessType_NONSTRICT_READ_WRITE() throws Exception {
assertThat(entityMemcachedRegion.buildAccessStrategy(AccessType.NONSTRICT_READ_WRITE)) | // Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/strategies/NonstrictReadWriteEntityRegionAccessStrategy.java
// public class NonstrictReadWriteEntityRegionAccessStrategy extends BaseEntityMemcachedRegionAccessStrategy {
// private Logger log = LoggerFactory.getLogger(NonstrictReadWriteEntityRegionAccessStrategy.class);
//
// public NonstrictReadWriteEntityRegionAccessStrategy(EntityMemcachedRegion entityMemcachedRegion) {
// super(entityMemcachedRegion);
// }
//
// @Override
// public boolean insert(Object key, Object value, Object version) throws CacheException {
// log.debug("region access strategy nonstrict-read-write entity insert() {} {}", getInternalRegion().getCacheNamespace(), key);
// // On nonstrict-read-write, Hibernate never calls this method.
// return false;
// }
//
// @Override
// public boolean afterInsert(Object key, Object value, Object version) throws CacheException {
// log.debug("region access strategy nonstrict-read-write entity afterInsert() {} {}", getInternalRegion().getCacheNamespace(), key);
// // On nonstrict-read-write, Hibernate never calls this method.
// return false;
// }
//
// /**
// * not necessary in nostrict-read-write
// *
// * @see org.hibernate.cache.spi.access.EntityRegionAccessStrategy
// */
// @Override
// public boolean update(Object key, Object value, Object currentVersion, Object previousVersion) throws CacheException {
// log.debug("region access strategy nonstrict-read-write entity update() {} {}", getInternalRegion().getCacheNamespace(), key);
// return false;
// }
//
// /**
// * need evict the key, after update.
// *
// * @see org.hibernate.cache.spi.access.EntityRegionAccessStrategy
// */
// @Override
// public boolean afterUpdate(Object key, Object value, Object currentVersion, Object previousVersion, SoftLock lock) throws CacheException {
// log.debug("region access strategy nonstrict-read-write entity afterUpdate() {} {}", getInternalRegion().getCacheNamespace(), key);
// getInternalRegion().evict(key);
// return false;
// }
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/strategies/ReadOnlyEntityRegionAccessStrategy.java
// public class ReadOnlyEntityRegionAccessStrategy extends BaseEntityMemcachedRegionAccessStrategy {
// private Logger log = LoggerFactory.getLogger(ReadOnlyEntityRegionAccessStrategy.class);
//
// public ReadOnlyEntityRegionAccessStrategy(EntityMemcachedRegion entityMemcachedRegion) {
// super(entityMemcachedRegion);
// }
//
// @Override
// public boolean insert(Object key, Object value, Object version) throws CacheException {
// log.debug("region access strategy readonly entity insert() {} {}", getInternalRegion().getCacheNamespace(), key);
// // On read-only, Hibernate never calls this method.
// return false;
// }
//
// @Override
// public boolean afterInsert(Object key, Object value, Object version) throws CacheException {
// log.debug("region access strategy readonly entity afterInsert() {} {}", getInternalRegion().getCacheNamespace(), key);
// // On read-only, Hibernate never calls this method.
// return false;
// }
//
// /**
// * read-onluy does not support update.
// */
// @Override
// public boolean update(Object key, Object value, Object currentVersion, Object previousVersion) throws CacheException {
// log.debug("region access strategy readonly entity update() {} {}", getInternalRegion().getCacheNamespace(), key);
// throw new UnsupportedOperationException("ReadOnly strategy does not support update.");
// }
//
// /**
// * read-only does not support update.
// */
// @Override
// public boolean afterUpdate(Object key, Object value, Object currentVersion, Object previousVersion, SoftLock lock) throws CacheException {
// log.debug("region access strategy readonly entity afterUpdate() {} {}", getInternalRegion().getCacheNamespace(), key);
// throw new UnsupportedOperationException("ReadOnly strategy does not support update.");
// }
// }
// Path: hibernate4-memcached-core/src/test/java/kr/pe/kwonnam/hibernate4memcached/regions/EntityMemcachedRegionTest.java
import kr.pe.kwonnam.hibernate4memcached.strategies.NonstrictReadWriteEntityRegionAccessStrategy;
import kr.pe.kwonnam.hibernate4memcached.strategies.ReadOnlyEntityRegionAccessStrategy;
import org.hibernate.cache.CacheException;
import org.hibernate.cache.spi.access.AccessType;
import org.junit.Test;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.hamcrest.CoreMatchers.containsString;
package kr.pe.kwonnam.hibernate4memcached.regions;
public class EntityMemcachedRegionTest extends AbstractFinalMemcachedRegionTest {
private EntityMemcachedRegion entityMemcachedRegion;
@Override
protected void afterSetUp() throws Exception {
entityMemcachedRegion = new EntityMemcachedRegion("Books", properties, metadata, settings, memcachedAdapter, hibernateCacheTimestamper);
}
@Test
public void buildAccessStrategy_AccessType_READ_ONLY() throws Exception {
assertThat(entityMemcachedRegion.buildAccessStrategy(AccessType.READ_ONLY))
.isExactlyInstanceOf(ReadOnlyEntityRegionAccessStrategy.class);
}
@Test
public void buildAccessStrategy_AccessType_NONSTRICT_READ_WRITE() throws Exception {
assertThat(entityMemcachedRegion.buildAccessStrategy(AccessType.NONSTRICT_READ_WRITE)) | .isExactlyInstanceOf(NonstrictReadWriteEntityRegionAccessStrategy.class); |
kwon37xi/hibernate4-memcached | hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/strategies/ReadOnlyNaturalIdRegionAccessStrategy.java | // Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/regions/NaturalIdMemcachedRegion.java
// public class NaturalIdMemcachedRegion extends TransactionalDataMemcachedRegion implements NaturalIdRegion {
// public NaturalIdMemcachedRegion(String regionName, OverridableReadOnlyProperties properties,
// CacheDataDescription metadata, Settings settings,
// MemcachedAdapter memcachedAdapter,
// HibernateCacheTimestamper hibernateCacheTimestamper) {
// super(new CacheNamespace(regionName, true), properties, metadata, settings, memcachedAdapter,
// hibernateCacheTimestamper);
// }
//
// @Override
// public NaturalIdRegionAccessStrategy buildAccessStrategy(AccessType accessType) throws CacheException {
// switch (accessType) {
// case READ_ONLY:
// return new ReadOnlyNaturalIdRegionAccessStrategy(this);
// case NONSTRICT_READ_WRITE:
// return new NonstrictReadWriteNaturalIdRegionAccessStrategy(this);
// default:
// throw new CacheException("Unsupported access strategy : " + accessType + ".");
// }
// }
// }
| import kr.pe.kwonnam.hibernate4memcached.regions.NaturalIdMemcachedRegion;
import org.hibernate.cache.CacheException;
import org.hibernate.cache.spi.access.SoftLock;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory; | package kr.pe.kwonnam.hibernate4memcached.strategies;
/**
* @author KwonNam Son ([email protected])
* @see org.hibernate.cache.spi.access.EntityRegionAccessStrategy
*/
public class ReadOnlyNaturalIdRegionAccessStrategy extends BaseNaturalIdMemcachedRegionAccessStrategy {
private Logger log = LoggerFactory.getLogger(ReadOnlyNaturalIdRegionAccessStrategy.class);
| // Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/regions/NaturalIdMemcachedRegion.java
// public class NaturalIdMemcachedRegion extends TransactionalDataMemcachedRegion implements NaturalIdRegion {
// public NaturalIdMemcachedRegion(String regionName, OverridableReadOnlyProperties properties,
// CacheDataDescription metadata, Settings settings,
// MemcachedAdapter memcachedAdapter,
// HibernateCacheTimestamper hibernateCacheTimestamper) {
// super(new CacheNamespace(regionName, true), properties, metadata, settings, memcachedAdapter,
// hibernateCacheTimestamper);
// }
//
// @Override
// public NaturalIdRegionAccessStrategy buildAccessStrategy(AccessType accessType) throws CacheException {
// switch (accessType) {
// case READ_ONLY:
// return new ReadOnlyNaturalIdRegionAccessStrategy(this);
// case NONSTRICT_READ_WRITE:
// return new NonstrictReadWriteNaturalIdRegionAccessStrategy(this);
// default:
// throw new CacheException("Unsupported access strategy : " + accessType + ".");
// }
// }
// }
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/strategies/ReadOnlyNaturalIdRegionAccessStrategy.java
import kr.pe.kwonnam.hibernate4memcached.regions.NaturalIdMemcachedRegion;
import org.hibernate.cache.CacheException;
import org.hibernate.cache.spi.access.SoftLock;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
package kr.pe.kwonnam.hibernate4memcached.strategies;
/**
* @author KwonNam Son ([email protected])
* @see org.hibernate.cache.spi.access.EntityRegionAccessStrategy
*/
public class ReadOnlyNaturalIdRegionAccessStrategy extends BaseNaturalIdMemcachedRegionAccessStrategy {
private Logger log = LoggerFactory.getLogger(ReadOnlyNaturalIdRegionAccessStrategy.class);
| public ReadOnlyNaturalIdRegionAccessStrategy(NaturalIdMemcachedRegion naturalIdMemcachedRegion) { |
kwon37xi/hibernate4-memcached | hibernate4-memcached-core/src/test/java/kr/pe/kwonnam/hibernate4memcached/strategies/NonstrictReadWriteNaturalIdRegionAccessStrategyTest.java | // Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/regions/NaturalIdMemcachedRegion.java
// public class NaturalIdMemcachedRegion extends TransactionalDataMemcachedRegion implements NaturalIdRegion {
// public NaturalIdMemcachedRegion(String regionName, OverridableReadOnlyProperties properties,
// CacheDataDescription metadata, Settings settings,
// MemcachedAdapter memcachedAdapter,
// HibernateCacheTimestamper hibernateCacheTimestamper) {
// super(new CacheNamespace(regionName, true), properties, metadata, settings, memcachedAdapter,
// hibernateCacheTimestamper);
// }
//
// @Override
// public NaturalIdRegionAccessStrategy buildAccessStrategy(AccessType accessType) throws CacheException {
// switch (accessType) {
// case READ_ONLY:
// return new ReadOnlyNaturalIdRegionAccessStrategy(this);
// case NONSTRICT_READ_WRITE:
// return new NonstrictReadWriteNaturalIdRegionAccessStrategy(this);
// default:
// throw new CacheException("Unsupported access strategy : " + accessType + ".");
// }
// }
// }
| import kr.pe.kwonnam.hibernate4memcached.regions.NaturalIdMemcachedRegion;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.mockito.Mockito.verify; | package kr.pe.kwonnam.hibernate4memcached.strategies;
@RunWith(MockitoJUnitRunner.class)
public class NonstrictReadWriteNaturalIdRegionAccessStrategyTest {
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Mock | // Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/regions/NaturalIdMemcachedRegion.java
// public class NaturalIdMemcachedRegion extends TransactionalDataMemcachedRegion implements NaturalIdRegion {
// public NaturalIdMemcachedRegion(String regionName, OverridableReadOnlyProperties properties,
// CacheDataDescription metadata, Settings settings,
// MemcachedAdapter memcachedAdapter,
// HibernateCacheTimestamper hibernateCacheTimestamper) {
// super(new CacheNamespace(regionName, true), properties, metadata, settings, memcachedAdapter,
// hibernateCacheTimestamper);
// }
//
// @Override
// public NaturalIdRegionAccessStrategy buildAccessStrategy(AccessType accessType) throws CacheException {
// switch (accessType) {
// case READ_ONLY:
// return new ReadOnlyNaturalIdRegionAccessStrategy(this);
// case NONSTRICT_READ_WRITE:
// return new NonstrictReadWriteNaturalIdRegionAccessStrategy(this);
// default:
// throw new CacheException("Unsupported access strategy : " + accessType + ".");
// }
// }
// }
// Path: hibernate4-memcached-core/src/test/java/kr/pe/kwonnam/hibernate4memcached/strategies/NonstrictReadWriteNaturalIdRegionAccessStrategyTest.java
import kr.pe.kwonnam.hibernate4memcached.regions.NaturalIdMemcachedRegion;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.mockito.Mockito.verify;
package kr.pe.kwonnam.hibernate4memcached.strategies;
@RunWith(MockitoJUnitRunner.class)
public class NonstrictReadWriteNaturalIdRegionAccessStrategyTest {
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Mock | private NaturalIdMemcachedRegion naturalIdMemcachedRegion; |
kwon37xi/hibernate4-memcached | hibernate4-memcached-core/src/test/java/kr/pe/kwonnam/hibernate4memcached/strategies/ReadOnlyNaturalIdRegionAccessStrategyTest.java | // Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/regions/NaturalIdMemcachedRegion.java
// public class NaturalIdMemcachedRegion extends TransactionalDataMemcachedRegion implements NaturalIdRegion {
// public NaturalIdMemcachedRegion(String regionName, OverridableReadOnlyProperties properties,
// CacheDataDescription metadata, Settings settings,
// MemcachedAdapter memcachedAdapter,
// HibernateCacheTimestamper hibernateCacheTimestamper) {
// super(new CacheNamespace(regionName, true), properties, metadata, settings, memcachedAdapter,
// hibernateCacheTimestamper);
// }
//
// @Override
// public NaturalIdRegionAccessStrategy buildAccessStrategy(AccessType accessType) throws CacheException {
// switch (accessType) {
// case READ_ONLY:
// return new ReadOnlyNaturalIdRegionAccessStrategy(this);
// case NONSTRICT_READ_WRITE:
// return new NonstrictReadWriteNaturalIdRegionAccessStrategy(this);
// default:
// throw new CacheException("Unsupported access strategy : " + accessType + ".");
// }
// }
// }
| import kr.pe.kwonnam.hibernate4memcached.regions.NaturalIdMemcachedRegion;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import static org.fest.assertions.api.Assertions.*; | package kr.pe.kwonnam.hibernate4memcached.strategies;
@RunWith(MockitoJUnitRunner.class)
public class ReadOnlyNaturalIdRegionAccessStrategyTest {
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Mock | // Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/regions/NaturalIdMemcachedRegion.java
// public class NaturalIdMemcachedRegion extends TransactionalDataMemcachedRegion implements NaturalIdRegion {
// public NaturalIdMemcachedRegion(String regionName, OverridableReadOnlyProperties properties,
// CacheDataDescription metadata, Settings settings,
// MemcachedAdapter memcachedAdapter,
// HibernateCacheTimestamper hibernateCacheTimestamper) {
// super(new CacheNamespace(regionName, true), properties, metadata, settings, memcachedAdapter,
// hibernateCacheTimestamper);
// }
//
// @Override
// public NaturalIdRegionAccessStrategy buildAccessStrategy(AccessType accessType) throws CacheException {
// switch (accessType) {
// case READ_ONLY:
// return new ReadOnlyNaturalIdRegionAccessStrategy(this);
// case NONSTRICT_READ_WRITE:
// return new NonstrictReadWriteNaturalIdRegionAccessStrategy(this);
// default:
// throw new CacheException("Unsupported access strategy : " + accessType + ".");
// }
// }
// }
// Path: hibernate4-memcached-core/src/test/java/kr/pe/kwonnam/hibernate4memcached/strategies/ReadOnlyNaturalIdRegionAccessStrategyTest.java
import kr.pe.kwonnam.hibernate4memcached.regions.NaturalIdMemcachedRegion;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import static org.fest.assertions.api.Assertions.*;
package kr.pe.kwonnam.hibernate4memcached.strategies;
@RunWith(MockitoJUnitRunner.class)
public class ReadOnlyNaturalIdRegionAccessStrategyTest {
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Mock | private NaturalIdMemcachedRegion naturalIdMemcachedRegion; |
kwon37xi/hibernate4-memcached | hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/regions/TimestampMemcachedRegion.java | // Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/memcached/CacheNamespace.java
// public class CacheNamespace implements Serializable {
// /**
// * name of region
// */
// private String name;
//
// /**
// * if this value is true, the memcached adapter should implement namespace pattern
// * or ignore namespace pattern.
// * <p/>
// * see <a href="https://code.google.com/p/memcached/wiki/NewProgrammingTricks#Namespacing">Memcached Namespacing</a>
// */
// private boolean namespaceExpirationRequired;
//
// public CacheNamespace(String name, boolean namespaceExpirationRequired) {
// this.name = name;
// this.namespaceExpirationRequired = namespaceExpirationRequired;
// }
//
// public String getName() {
// return name;
// }
//
// public boolean isNamespaceExpirationRequired() {
// return namespaceExpirationRequired;
// }
//
// @Override
// public boolean equals(Object o) {
// if (o == null) {
// return false;
// }
// if (this == o) {
// return true;
// }
// if (getClass() != o.getClass()) {
// return false;
// }
//
// CacheNamespace otherCacheNamespace = (CacheNamespace) o;
//
// return new EqualsBuilder().append(name, otherCacheNamespace.name)
// .append(namespaceExpirationRequired, otherCacheNamespace.namespaceExpirationRequired).isEquals();
// }
//
// @Override
// public int hashCode() {
// return new HashCodeBuilder().append(name).append(namespaceExpirationRequired).toHashCode();
// }
//
// @Override
// public String toString() {
// return new ToStringBuilder(this).append("name", name).append("namespaceExpirationRequired", namespaceExpirationRequired).toString();
// }
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/memcached/MemcachedAdapter.java
// public interface MemcachedAdapter {
// /**
// * Lifecycle callback to perform initialization.
// *
// * @param properties the defined cfg properties
// */
// void init(OverridableReadOnlyProperties properties);
//
// /**
// * Lifecycle callback to perform cleanup.
// */
// void destroy();
//
// /**
// * get value from memcached
// */
// Object get(CacheNamespace cacheNamespace, String key);
//
// /**
// * set value to memcache with expirySeconds
// */
// void set(CacheNamespace cacheNamespace, String key, Object value, int expirySeconds);
//
// /**
// * delete key from memcached
// */
// void delete(CacheNamespace cacheNamespace, String key);
//
// /**
// * increase given increment couter and return new value.
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param by the amount of increment
// * @param defaultValue default value when the key missing
// * @return increased value
// */
// long increaseCounter(CacheNamespace cacheNamespace, String key, long by, long defaultValue, int expirySeconds);
//
// /**
// * get current value from increment counter
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param defaultValue default value when the key missing
// * @return current value of counter without increment
// */
// long getCounter(CacheNamespace cacheNamespace, String key, long defaultValue, int expirySeconds);
//
// /**
// * Evict namespace
// *
// * @param cacheNamespace cache namespace
// */
// void evictAll(CacheNamespace cacheNamespace);
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/timestamper/HibernateCacheTimestamper.java
// public interface HibernateCacheTimestamper {
//
// void setSettings(Settings settings);
//
// void setProperties(OverridableReadOnlyProperties properties);
//
// void setMemcachedAdapter(MemcachedAdapter memcachedAdapter);
//
// /** initialize timestamp object */
// void init();
//
// /** get next timestamp */
// long next();
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/util/OverridableReadOnlyProperties.java
// public interface OverridableReadOnlyProperties {
// String getProperty(String key);
//
// String getProperty(String key, String defaultValue);
//
// String getRequiredProperty(String key);
// }
| import kr.pe.kwonnam.hibernate4memcached.memcached.CacheNamespace;
import kr.pe.kwonnam.hibernate4memcached.memcached.MemcachedAdapter;
import kr.pe.kwonnam.hibernate4memcached.timestamper.HibernateCacheTimestamper;
import kr.pe.kwonnam.hibernate4memcached.util.OverridableReadOnlyProperties;
import org.hibernate.cache.spi.TimestampsRegion;
import org.hibernate.cfg.Settings; | package kr.pe.kwonnam.hibernate4memcached.regions;
/**
* {@link org.hibernate.cache.spi.TimestampsRegion} has no concurrency strategy.
* It deals <code>[cache-region-prefix.]org.hibernate.cache.spi.UpdateTimestampsCache</code>.
* <p/>
*
* This region should have very long expiry seconds.
*
* @author KwonNam Son ([email protected])
*/
public class TimestampMemcachedRegion extends GeneralDataMemcachedRegion implements TimestampsRegion {
public TimestampMemcachedRegion(String regionName, OverridableReadOnlyProperties properties, Settings settings, | // Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/memcached/CacheNamespace.java
// public class CacheNamespace implements Serializable {
// /**
// * name of region
// */
// private String name;
//
// /**
// * if this value is true, the memcached adapter should implement namespace pattern
// * or ignore namespace pattern.
// * <p/>
// * see <a href="https://code.google.com/p/memcached/wiki/NewProgrammingTricks#Namespacing">Memcached Namespacing</a>
// */
// private boolean namespaceExpirationRequired;
//
// public CacheNamespace(String name, boolean namespaceExpirationRequired) {
// this.name = name;
// this.namespaceExpirationRequired = namespaceExpirationRequired;
// }
//
// public String getName() {
// return name;
// }
//
// public boolean isNamespaceExpirationRequired() {
// return namespaceExpirationRequired;
// }
//
// @Override
// public boolean equals(Object o) {
// if (o == null) {
// return false;
// }
// if (this == o) {
// return true;
// }
// if (getClass() != o.getClass()) {
// return false;
// }
//
// CacheNamespace otherCacheNamespace = (CacheNamespace) o;
//
// return new EqualsBuilder().append(name, otherCacheNamespace.name)
// .append(namespaceExpirationRequired, otherCacheNamespace.namespaceExpirationRequired).isEquals();
// }
//
// @Override
// public int hashCode() {
// return new HashCodeBuilder().append(name).append(namespaceExpirationRequired).toHashCode();
// }
//
// @Override
// public String toString() {
// return new ToStringBuilder(this).append("name", name).append("namespaceExpirationRequired", namespaceExpirationRequired).toString();
// }
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/memcached/MemcachedAdapter.java
// public interface MemcachedAdapter {
// /**
// * Lifecycle callback to perform initialization.
// *
// * @param properties the defined cfg properties
// */
// void init(OverridableReadOnlyProperties properties);
//
// /**
// * Lifecycle callback to perform cleanup.
// */
// void destroy();
//
// /**
// * get value from memcached
// */
// Object get(CacheNamespace cacheNamespace, String key);
//
// /**
// * set value to memcache with expirySeconds
// */
// void set(CacheNamespace cacheNamespace, String key, Object value, int expirySeconds);
//
// /**
// * delete key from memcached
// */
// void delete(CacheNamespace cacheNamespace, String key);
//
// /**
// * increase given increment couter and return new value.
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param by the amount of increment
// * @param defaultValue default value when the key missing
// * @return increased value
// */
// long increaseCounter(CacheNamespace cacheNamespace, String key, long by, long defaultValue, int expirySeconds);
//
// /**
// * get current value from increment counter
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param defaultValue default value when the key missing
// * @return current value of counter without increment
// */
// long getCounter(CacheNamespace cacheNamespace, String key, long defaultValue, int expirySeconds);
//
// /**
// * Evict namespace
// *
// * @param cacheNamespace cache namespace
// */
// void evictAll(CacheNamespace cacheNamespace);
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/timestamper/HibernateCacheTimestamper.java
// public interface HibernateCacheTimestamper {
//
// void setSettings(Settings settings);
//
// void setProperties(OverridableReadOnlyProperties properties);
//
// void setMemcachedAdapter(MemcachedAdapter memcachedAdapter);
//
// /** initialize timestamp object */
// void init();
//
// /** get next timestamp */
// long next();
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/util/OverridableReadOnlyProperties.java
// public interface OverridableReadOnlyProperties {
// String getProperty(String key);
//
// String getProperty(String key, String defaultValue);
//
// String getRequiredProperty(String key);
// }
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/regions/TimestampMemcachedRegion.java
import kr.pe.kwonnam.hibernate4memcached.memcached.CacheNamespace;
import kr.pe.kwonnam.hibernate4memcached.memcached.MemcachedAdapter;
import kr.pe.kwonnam.hibernate4memcached.timestamper.HibernateCacheTimestamper;
import kr.pe.kwonnam.hibernate4memcached.util.OverridableReadOnlyProperties;
import org.hibernate.cache.spi.TimestampsRegion;
import org.hibernate.cfg.Settings;
package kr.pe.kwonnam.hibernate4memcached.regions;
/**
* {@link org.hibernate.cache.spi.TimestampsRegion} has no concurrency strategy.
* It deals <code>[cache-region-prefix.]org.hibernate.cache.spi.UpdateTimestampsCache</code>.
* <p/>
*
* This region should have very long expiry seconds.
*
* @author KwonNam Son ([email protected])
*/
public class TimestampMemcachedRegion extends GeneralDataMemcachedRegion implements TimestampsRegion {
public TimestampMemcachedRegion(String regionName, OverridableReadOnlyProperties properties, Settings settings, | MemcachedAdapter memcachedAdapter, |
kwon37xi/hibernate4-memcached | hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/regions/TimestampMemcachedRegion.java | // Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/memcached/CacheNamespace.java
// public class CacheNamespace implements Serializable {
// /**
// * name of region
// */
// private String name;
//
// /**
// * if this value is true, the memcached adapter should implement namespace pattern
// * or ignore namespace pattern.
// * <p/>
// * see <a href="https://code.google.com/p/memcached/wiki/NewProgrammingTricks#Namespacing">Memcached Namespacing</a>
// */
// private boolean namespaceExpirationRequired;
//
// public CacheNamespace(String name, boolean namespaceExpirationRequired) {
// this.name = name;
// this.namespaceExpirationRequired = namespaceExpirationRequired;
// }
//
// public String getName() {
// return name;
// }
//
// public boolean isNamespaceExpirationRequired() {
// return namespaceExpirationRequired;
// }
//
// @Override
// public boolean equals(Object o) {
// if (o == null) {
// return false;
// }
// if (this == o) {
// return true;
// }
// if (getClass() != o.getClass()) {
// return false;
// }
//
// CacheNamespace otherCacheNamespace = (CacheNamespace) o;
//
// return new EqualsBuilder().append(name, otherCacheNamespace.name)
// .append(namespaceExpirationRequired, otherCacheNamespace.namespaceExpirationRequired).isEquals();
// }
//
// @Override
// public int hashCode() {
// return new HashCodeBuilder().append(name).append(namespaceExpirationRequired).toHashCode();
// }
//
// @Override
// public String toString() {
// return new ToStringBuilder(this).append("name", name).append("namespaceExpirationRequired", namespaceExpirationRequired).toString();
// }
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/memcached/MemcachedAdapter.java
// public interface MemcachedAdapter {
// /**
// * Lifecycle callback to perform initialization.
// *
// * @param properties the defined cfg properties
// */
// void init(OverridableReadOnlyProperties properties);
//
// /**
// * Lifecycle callback to perform cleanup.
// */
// void destroy();
//
// /**
// * get value from memcached
// */
// Object get(CacheNamespace cacheNamespace, String key);
//
// /**
// * set value to memcache with expirySeconds
// */
// void set(CacheNamespace cacheNamespace, String key, Object value, int expirySeconds);
//
// /**
// * delete key from memcached
// */
// void delete(CacheNamespace cacheNamespace, String key);
//
// /**
// * increase given increment couter and return new value.
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param by the amount of increment
// * @param defaultValue default value when the key missing
// * @return increased value
// */
// long increaseCounter(CacheNamespace cacheNamespace, String key, long by, long defaultValue, int expirySeconds);
//
// /**
// * get current value from increment counter
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param defaultValue default value when the key missing
// * @return current value of counter without increment
// */
// long getCounter(CacheNamespace cacheNamespace, String key, long defaultValue, int expirySeconds);
//
// /**
// * Evict namespace
// *
// * @param cacheNamespace cache namespace
// */
// void evictAll(CacheNamespace cacheNamespace);
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/timestamper/HibernateCacheTimestamper.java
// public interface HibernateCacheTimestamper {
//
// void setSettings(Settings settings);
//
// void setProperties(OverridableReadOnlyProperties properties);
//
// void setMemcachedAdapter(MemcachedAdapter memcachedAdapter);
//
// /** initialize timestamp object */
// void init();
//
// /** get next timestamp */
// long next();
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/util/OverridableReadOnlyProperties.java
// public interface OverridableReadOnlyProperties {
// String getProperty(String key);
//
// String getProperty(String key, String defaultValue);
//
// String getRequiredProperty(String key);
// }
| import kr.pe.kwonnam.hibernate4memcached.memcached.CacheNamespace;
import kr.pe.kwonnam.hibernate4memcached.memcached.MemcachedAdapter;
import kr.pe.kwonnam.hibernate4memcached.timestamper.HibernateCacheTimestamper;
import kr.pe.kwonnam.hibernate4memcached.util.OverridableReadOnlyProperties;
import org.hibernate.cache.spi.TimestampsRegion;
import org.hibernate.cfg.Settings; | package kr.pe.kwonnam.hibernate4memcached.regions;
/**
* {@link org.hibernate.cache.spi.TimestampsRegion} has no concurrency strategy.
* It deals <code>[cache-region-prefix.]org.hibernate.cache.spi.UpdateTimestampsCache</code>.
* <p/>
*
* This region should have very long expiry seconds.
*
* @author KwonNam Son ([email protected])
*/
public class TimestampMemcachedRegion extends GeneralDataMemcachedRegion implements TimestampsRegion {
public TimestampMemcachedRegion(String regionName, OverridableReadOnlyProperties properties, Settings settings,
MemcachedAdapter memcachedAdapter, | // Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/memcached/CacheNamespace.java
// public class CacheNamespace implements Serializable {
// /**
// * name of region
// */
// private String name;
//
// /**
// * if this value is true, the memcached adapter should implement namespace pattern
// * or ignore namespace pattern.
// * <p/>
// * see <a href="https://code.google.com/p/memcached/wiki/NewProgrammingTricks#Namespacing">Memcached Namespacing</a>
// */
// private boolean namespaceExpirationRequired;
//
// public CacheNamespace(String name, boolean namespaceExpirationRequired) {
// this.name = name;
// this.namespaceExpirationRequired = namespaceExpirationRequired;
// }
//
// public String getName() {
// return name;
// }
//
// public boolean isNamespaceExpirationRequired() {
// return namespaceExpirationRequired;
// }
//
// @Override
// public boolean equals(Object o) {
// if (o == null) {
// return false;
// }
// if (this == o) {
// return true;
// }
// if (getClass() != o.getClass()) {
// return false;
// }
//
// CacheNamespace otherCacheNamespace = (CacheNamespace) o;
//
// return new EqualsBuilder().append(name, otherCacheNamespace.name)
// .append(namespaceExpirationRequired, otherCacheNamespace.namespaceExpirationRequired).isEquals();
// }
//
// @Override
// public int hashCode() {
// return new HashCodeBuilder().append(name).append(namespaceExpirationRequired).toHashCode();
// }
//
// @Override
// public String toString() {
// return new ToStringBuilder(this).append("name", name).append("namespaceExpirationRequired", namespaceExpirationRequired).toString();
// }
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/memcached/MemcachedAdapter.java
// public interface MemcachedAdapter {
// /**
// * Lifecycle callback to perform initialization.
// *
// * @param properties the defined cfg properties
// */
// void init(OverridableReadOnlyProperties properties);
//
// /**
// * Lifecycle callback to perform cleanup.
// */
// void destroy();
//
// /**
// * get value from memcached
// */
// Object get(CacheNamespace cacheNamespace, String key);
//
// /**
// * set value to memcache with expirySeconds
// */
// void set(CacheNamespace cacheNamespace, String key, Object value, int expirySeconds);
//
// /**
// * delete key from memcached
// */
// void delete(CacheNamespace cacheNamespace, String key);
//
// /**
// * increase given increment couter and return new value.
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param by the amount of increment
// * @param defaultValue default value when the key missing
// * @return increased value
// */
// long increaseCounter(CacheNamespace cacheNamespace, String key, long by, long defaultValue, int expirySeconds);
//
// /**
// * get current value from increment counter
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param defaultValue default value when the key missing
// * @return current value of counter without increment
// */
// long getCounter(CacheNamespace cacheNamespace, String key, long defaultValue, int expirySeconds);
//
// /**
// * Evict namespace
// *
// * @param cacheNamespace cache namespace
// */
// void evictAll(CacheNamespace cacheNamespace);
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/timestamper/HibernateCacheTimestamper.java
// public interface HibernateCacheTimestamper {
//
// void setSettings(Settings settings);
//
// void setProperties(OverridableReadOnlyProperties properties);
//
// void setMemcachedAdapter(MemcachedAdapter memcachedAdapter);
//
// /** initialize timestamp object */
// void init();
//
// /** get next timestamp */
// long next();
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/util/OverridableReadOnlyProperties.java
// public interface OverridableReadOnlyProperties {
// String getProperty(String key);
//
// String getProperty(String key, String defaultValue);
//
// String getRequiredProperty(String key);
// }
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/regions/TimestampMemcachedRegion.java
import kr.pe.kwonnam.hibernate4memcached.memcached.CacheNamespace;
import kr.pe.kwonnam.hibernate4memcached.memcached.MemcachedAdapter;
import kr.pe.kwonnam.hibernate4memcached.timestamper.HibernateCacheTimestamper;
import kr.pe.kwonnam.hibernate4memcached.util.OverridableReadOnlyProperties;
import org.hibernate.cache.spi.TimestampsRegion;
import org.hibernate.cfg.Settings;
package kr.pe.kwonnam.hibernate4memcached.regions;
/**
* {@link org.hibernate.cache.spi.TimestampsRegion} has no concurrency strategy.
* It deals <code>[cache-region-prefix.]org.hibernate.cache.spi.UpdateTimestampsCache</code>.
* <p/>
*
* This region should have very long expiry seconds.
*
* @author KwonNam Son ([email protected])
*/
public class TimestampMemcachedRegion extends GeneralDataMemcachedRegion implements TimestampsRegion {
public TimestampMemcachedRegion(String regionName, OverridableReadOnlyProperties properties, Settings settings,
MemcachedAdapter memcachedAdapter, | HibernateCacheTimestamper hibernateCacheTimestamper) { |
kwon37xi/hibernate4-memcached | hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/regions/TimestampMemcachedRegion.java | // Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/memcached/CacheNamespace.java
// public class CacheNamespace implements Serializable {
// /**
// * name of region
// */
// private String name;
//
// /**
// * if this value is true, the memcached adapter should implement namespace pattern
// * or ignore namespace pattern.
// * <p/>
// * see <a href="https://code.google.com/p/memcached/wiki/NewProgrammingTricks#Namespacing">Memcached Namespacing</a>
// */
// private boolean namespaceExpirationRequired;
//
// public CacheNamespace(String name, boolean namespaceExpirationRequired) {
// this.name = name;
// this.namespaceExpirationRequired = namespaceExpirationRequired;
// }
//
// public String getName() {
// return name;
// }
//
// public boolean isNamespaceExpirationRequired() {
// return namespaceExpirationRequired;
// }
//
// @Override
// public boolean equals(Object o) {
// if (o == null) {
// return false;
// }
// if (this == o) {
// return true;
// }
// if (getClass() != o.getClass()) {
// return false;
// }
//
// CacheNamespace otherCacheNamespace = (CacheNamespace) o;
//
// return new EqualsBuilder().append(name, otherCacheNamespace.name)
// .append(namespaceExpirationRequired, otherCacheNamespace.namespaceExpirationRequired).isEquals();
// }
//
// @Override
// public int hashCode() {
// return new HashCodeBuilder().append(name).append(namespaceExpirationRequired).toHashCode();
// }
//
// @Override
// public String toString() {
// return new ToStringBuilder(this).append("name", name).append("namespaceExpirationRequired", namespaceExpirationRequired).toString();
// }
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/memcached/MemcachedAdapter.java
// public interface MemcachedAdapter {
// /**
// * Lifecycle callback to perform initialization.
// *
// * @param properties the defined cfg properties
// */
// void init(OverridableReadOnlyProperties properties);
//
// /**
// * Lifecycle callback to perform cleanup.
// */
// void destroy();
//
// /**
// * get value from memcached
// */
// Object get(CacheNamespace cacheNamespace, String key);
//
// /**
// * set value to memcache with expirySeconds
// */
// void set(CacheNamespace cacheNamespace, String key, Object value, int expirySeconds);
//
// /**
// * delete key from memcached
// */
// void delete(CacheNamespace cacheNamespace, String key);
//
// /**
// * increase given increment couter and return new value.
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param by the amount of increment
// * @param defaultValue default value when the key missing
// * @return increased value
// */
// long increaseCounter(CacheNamespace cacheNamespace, String key, long by, long defaultValue, int expirySeconds);
//
// /**
// * get current value from increment counter
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param defaultValue default value when the key missing
// * @return current value of counter without increment
// */
// long getCounter(CacheNamespace cacheNamespace, String key, long defaultValue, int expirySeconds);
//
// /**
// * Evict namespace
// *
// * @param cacheNamespace cache namespace
// */
// void evictAll(CacheNamespace cacheNamespace);
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/timestamper/HibernateCacheTimestamper.java
// public interface HibernateCacheTimestamper {
//
// void setSettings(Settings settings);
//
// void setProperties(OverridableReadOnlyProperties properties);
//
// void setMemcachedAdapter(MemcachedAdapter memcachedAdapter);
//
// /** initialize timestamp object */
// void init();
//
// /** get next timestamp */
// long next();
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/util/OverridableReadOnlyProperties.java
// public interface OverridableReadOnlyProperties {
// String getProperty(String key);
//
// String getProperty(String key, String defaultValue);
//
// String getRequiredProperty(String key);
// }
| import kr.pe.kwonnam.hibernate4memcached.memcached.CacheNamespace;
import kr.pe.kwonnam.hibernate4memcached.memcached.MemcachedAdapter;
import kr.pe.kwonnam.hibernate4memcached.timestamper.HibernateCacheTimestamper;
import kr.pe.kwonnam.hibernate4memcached.util.OverridableReadOnlyProperties;
import org.hibernate.cache.spi.TimestampsRegion;
import org.hibernate.cfg.Settings; | package kr.pe.kwonnam.hibernate4memcached.regions;
/**
* {@link org.hibernate.cache.spi.TimestampsRegion} has no concurrency strategy.
* It deals <code>[cache-region-prefix.]org.hibernate.cache.spi.UpdateTimestampsCache</code>.
* <p/>
*
* This region should have very long expiry seconds.
*
* @author KwonNam Son ([email protected])
*/
public class TimestampMemcachedRegion extends GeneralDataMemcachedRegion implements TimestampsRegion {
public TimestampMemcachedRegion(String regionName, OverridableReadOnlyProperties properties, Settings settings,
MemcachedAdapter memcachedAdapter,
HibernateCacheTimestamper hibernateCacheTimestamper) { | // Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/memcached/CacheNamespace.java
// public class CacheNamespace implements Serializable {
// /**
// * name of region
// */
// private String name;
//
// /**
// * if this value is true, the memcached adapter should implement namespace pattern
// * or ignore namespace pattern.
// * <p/>
// * see <a href="https://code.google.com/p/memcached/wiki/NewProgrammingTricks#Namespacing">Memcached Namespacing</a>
// */
// private boolean namespaceExpirationRequired;
//
// public CacheNamespace(String name, boolean namespaceExpirationRequired) {
// this.name = name;
// this.namespaceExpirationRequired = namespaceExpirationRequired;
// }
//
// public String getName() {
// return name;
// }
//
// public boolean isNamespaceExpirationRequired() {
// return namespaceExpirationRequired;
// }
//
// @Override
// public boolean equals(Object o) {
// if (o == null) {
// return false;
// }
// if (this == o) {
// return true;
// }
// if (getClass() != o.getClass()) {
// return false;
// }
//
// CacheNamespace otherCacheNamespace = (CacheNamespace) o;
//
// return new EqualsBuilder().append(name, otherCacheNamespace.name)
// .append(namespaceExpirationRequired, otherCacheNamespace.namespaceExpirationRequired).isEquals();
// }
//
// @Override
// public int hashCode() {
// return new HashCodeBuilder().append(name).append(namespaceExpirationRequired).toHashCode();
// }
//
// @Override
// public String toString() {
// return new ToStringBuilder(this).append("name", name).append("namespaceExpirationRequired", namespaceExpirationRequired).toString();
// }
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/memcached/MemcachedAdapter.java
// public interface MemcachedAdapter {
// /**
// * Lifecycle callback to perform initialization.
// *
// * @param properties the defined cfg properties
// */
// void init(OverridableReadOnlyProperties properties);
//
// /**
// * Lifecycle callback to perform cleanup.
// */
// void destroy();
//
// /**
// * get value from memcached
// */
// Object get(CacheNamespace cacheNamespace, String key);
//
// /**
// * set value to memcache with expirySeconds
// */
// void set(CacheNamespace cacheNamespace, String key, Object value, int expirySeconds);
//
// /**
// * delete key from memcached
// */
// void delete(CacheNamespace cacheNamespace, String key);
//
// /**
// * increase given increment couter and return new value.
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param by the amount of increment
// * @param defaultValue default value when the key missing
// * @return increased value
// */
// long increaseCounter(CacheNamespace cacheNamespace, String key, long by, long defaultValue, int expirySeconds);
//
// /**
// * get current value from increment counter
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param defaultValue default value when the key missing
// * @return current value of counter without increment
// */
// long getCounter(CacheNamespace cacheNamespace, String key, long defaultValue, int expirySeconds);
//
// /**
// * Evict namespace
// *
// * @param cacheNamespace cache namespace
// */
// void evictAll(CacheNamespace cacheNamespace);
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/timestamper/HibernateCacheTimestamper.java
// public interface HibernateCacheTimestamper {
//
// void setSettings(Settings settings);
//
// void setProperties(OverridableReadOnlyProperties properties);
//
// void setMemcachedAdapter(MemcachedAdapter memcachedAdapter);
//
// /** initialize timestamp object */
// void init();
//
// /** get next timestamp */
// long next();
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/util/OverridableReadOnlyProperties.java
// public interface OverridableReadOnlyProperties {
// String getProperty(String key);
//
// String getProperty(String key, String defaultValue);
//
// String getRequiredProperty(String key);
// }
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/regions/TimestampMemcachedRegion.java
import kr.pe.kwonnam.hibernate4memcached.memcached.CacheNamespace;
import kr.pe.kwonnam.hibernate4memcached.memcached.MemcachedAdapter;
import kr.pe.kwonnam.hibernate4memcached.timestamper.HibernateCacheTimestamper;
import kr.pe.kwonnam.hibernate4memcached.util.OverridableReadOnlyProperties;
import org.hibernate.cache.spi.TimestampsRegion;
import org.hibernate.cfg.Settings;
package kr.pe.kwonnam.hibernate4memcached.regions;
/**
* {@link org.hibernate.cache.spi.TimestampsRegion} has no concurrency strategy.
* It deals <code>[cache-region-prefix.]org.hibernate.cache.spi.UpdateTimestampsCache</code>.
* <p/>
*
* This region should have very long expiry seconds.
*
* @author KwonNam Son ([email protected])
*/
public class TimestampMemcachedRegion extends GeneralDataMemcachedRegion implements TimestampsRegion {
public TimestampMemcachedRegion(String regionName, OverridableReadOnlyProperties properties, Settings settings,
MemcachedAdapter memcachedAdapter,
HibernateCacheTimestamper hibernateCacheTimestamper) { | super(new CacheNamespace(regionName, false), properties, null, settings, memcachedAdapter, |
kwon37xi/hibernate4-memcached | hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/regions/QueryResultsMemcachedRegion.java | // Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/memcached/CacheNamespace.java
// public class CacheNamespace implements Serializable {
// /**
// * name of region
// */
// private String name;
//
// /**
// * if this value is true, the memcached adapter should implement namespace pattern
// * or ignore namespace pattern.
// * <p/>
// * see <a href="https://code.google.com/p/memcached/wiki/NewProgrammingTricks#Namespacing">Memcached Namespacing</a>
// */
// private boolean namespaceExpirationRequired;
//
// public CacheNamespace(String name, boolean namespaceExpirationRequired) {
// this.name = name;
// this.namespaceExpirationRequired = namespaceExpirationRequired;
// }
//
// public String getName() {
// return name;
// }
//
// public boolean isNamespaceExpirationRequired() {
// return namespaceExpirationRequired;
// }
//
// @Override
// public boolean equals(Object o) {
// if (o == null) {
// return false;
// }
// if (this == o) {
// return true;
// }
// if (getClass() != o.getClass()) {
// return false;
// }
//
// CacheNamespace otherCacheNamespace = (CacheNamespace) o;
//
// return new EqualsBuilder().append(name, otherCacheNamespace.name)
// .append(namespaceExpirationRequired, otherCacheNamespace.namespaceExpirationRequired).isEquals();
// }
//
// @Override
// public int hashCode() {
// return new HashCodeBuilder().append(name).append(namespaceExpirationRequired).toHashCode();
// }
//
// @Override
// public String toString() {
// return new ToStringBuilder(this).append("name", name).append("namespaceExpirationRequired", namespaceExpirationRequired).toString();
// }
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/memcached/MemcachedAdapter.java
// public interface MemcachedAdapter {
// /**
// * Lifecycle callback to perform initialization.
// *
// * @param properties the defined cfg properties
// */
// void init(OverridableReadOnlyProperties properties);
//
// /**
// * Lifecycle callback to perform cleanup.
// */
// void destroy();
//
// /**
// * get value from memcached
// */
// Object get(CacheNamespace cacheNamespace, String key);
//
// /**
// * set value to memcache with expirySeconds
// */
// void set(CacheNamespace cacheNamespace, String key, Object value, int expirySeconds);
//
// /**
// * delete key from memcached
// */
// void delete(CacheNamespace cacheNamespace, String key);
//
// /**
// * increase given increment couter and return new value.
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param by the amount of increment
// * @param defaultValue default value when the key missing
// * @return increased value
// */
// long increaseCounter(CacheNamespace cacheNamespace, String key, long by, long defaultValue, int expirySeconds);
//
// /**
// * get current value from increment counter
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param defaultValue default value when the key missing
// * @return current value of counter without increment
// */
// long getCounter(CacheNamespace cacheNamespace, String key, long defaultValue, int expirySeconds);
//
// /**
// * Evict namespace
// *
// * @param cacheNamespace cache namespace
// */
// void evictAll(CacheNamespace cacheNamespace);
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/timestamper/HibernateCacheTimestamper.java
// public interface HibernateCacheTimestamper {
//
// void setSettings(Settings settings);
//
// void setProperties(OverridableReadOnlyProperties properties);
//
// void setMemcachedAdapter(MemcachedAdapter memcachedAdapter);
//
// /** initialize timestamp object */
// void init();
//
// /** get next timestamp */
// long next();
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/util/OverridableReadOnlyProperties.java
// public interface OverridableReadOnlyProperties {
// String getProperty(String key);
//
// String getProperty(String key, String defaultValue);
//
// String getRequiredProperty(String key);
// }
| import kr.pe.kwonnam.hibernate4memcached.memcached.CacheNamespace;
import kr.pe.kwonnam.hibernate4memcached.memcached.MemcachedAdapter;
import kr.pe.kwonnam.hibernate4memcached.timestamper.HibernateCacheTimestamper;
import kr.pe.kwonnam.hibernate4memcached.util.OverridableReadOnlyProperties;
import org.apache.commons.codec.digest.DigestUtils;
import org.hibernate.cache.spi.QueryResultsRegion;
import org.hibernate.cfg.Settings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory; | package kr.pe.kwonnam.hibernate4memcached.regions;
/**
* {@link org.hibernate.cache.spi.QueryResultsRegion}은 strategy가 없다.
*
* @author KwonNam Son ([email protected])
*/
public class QueryResultsMemcachedRegion extends GeneralDataMemcachedRegion implements QueryResultsRegion {
private Logger log = LoggerFactory.getLogger(QueryResultsMemcachedRegion.class);
| // Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/memcached/CacheNamespace.java
// public class CacheNamespace implements Serializable {
// /**
// * name of region
// */
// private String name;
//
// /**
// * if this value is true, the memcached adapter should implement namespace pattern
// * or ignore namespace pattern.
// * <p/>
// * see <a href="https://code.google.com/p/memcached/wiki/NewProgrammingTricks#Namespacing">Memcached Namespacing</a>
// */
// private boolean namespaceExpirationRequired;
//
// public CacheNamespace(String name, boolean namespaceExpirationRequired) {
// this.name = name;
// this.namespaceExpirationRequired = namespaceExpirationRequired;
// }
//
// public String getName() {
// return name;
// }
//
// public boolean isNamespaceExpirationRequired() {
// return namespaceExpirationRequired;
// }
//
// @Override
// public boolean equals(Object o) {
// if (o == null) {
// return false;
// }
// if (this == o) {
// return true;
// }
// if (getClass() != o.getClass()) {
// return false;
// }
//
// CacheNamespace otherCacheNamespace = (CacheNamespace) o;
//
// return new EqualsBuilder().append(name, otherCacheNamespace.name)
// .append(namespaceExpirationRequired, otherCacheNamespace.namespaceExpirationRequired).isEquals();
// }
//
// @Override
// public int hashCode() {
// return new HashCodeBuilder().append(name).append(namespaceExpirationRequired).toHashCode();
// }
//
// @Override
// public String toString() {
// return new ToStringBuilder(this).append("name", name).append("namespaceExpirationRequired", namespaceExpirationRequired).toString();
// }
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/memcached/MemcachedAdapter.java
// public interface MemcachedAdapter {
// /**
// * Lifecycle callback to perform initialization.
// *
// * @param properties the defined cfg properties
// */
// void init(OverridableReadOnlyProperties properties);
//
// /**
// * Lifecycle callback to perform cleanup.
// */
// void destroy();
//
// /**
// * get value from memcached
// */
// Object get(CacheNamespace cacheNamespace, String key);
//
// /**
// * set value to memcache with expirySeconds
// */
// void set(CacheNamespace cacheNamespace, String key, Object value, int expirySeconds);
//
// /**
// * delete key from memcached
// */
// void delete(CacheNamespace cacheNamespace, String key);
//
// /**
// * increase given increment couter and return new value.
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param by the amount of increment
// * @param defaultValue default value when the key missing
// * @return increased value
// */
// long increaseCounter(CacheNamespace cacheNamespace, String key, long by, long defaultValue, int expirySeconds);
//
// /**
// * get current value from increment counter
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param defaultValue default value when the key missing
// * @return current value of counter without increment
// */
// long getCounter(CacheNamespace cacheNamespace, String key, long defaultValue, int expirySeconds);
//
// /**
// * Evict namespace
// *
// * @param cacheNamespace cache namespace
// */
// void evictAll(CacheNamespace cacheNamespace);
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/timestamper/HibernateCacheTimestamper.java
// public interface HibernateCacheTimestamper {
//
// void setSettings(Settings settings);
//
// void setProperties(OverridableReadOnlyProperties properties);
//
// void setMemcachedAdapter(MemcachedAdapter memcachedAdapter);
//
// /** initialize timestamp object */
// void init();
//
// /** get next timestamp */
// long next();
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/util/OverridableReadOnlyProperties.java
// public interface OverridableReadOnlyProperties {
// String getProperty(String key);
//
// String getProperty(String key, String defaultValue);
//
// String getRequiredProperty(String key);
// }
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/regions/QueryResultsMemcachedRegion.java
import kr.pe.kwonnam.hibernate4memcached.memcached.CacheNamespace;
import kr.pe.kwonnam.hibernate4memcached.memcached.MemcachedAdapter;
import kr.pe.kwonnam.hibernate4memcached.timestamper.HibernateCacheTimestamper;
import kr.pe.kwonnam.hibernate4memcached.util.OverridableReadOnlyProperties;
import org.apache.commons.codec.digest.DigestUtils;
import org.hibernate.cache.spi.QueryResultsRegion;
import org.hibernate.cfg.Settings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
package kr.pe.kwonnam.hibernate4memcached.regions;
/**
* {@link org.hibernate.cache.spi.QueryResultsRegion}은 strategy가 없다.
*
* @author KwonNam Son ([email protected])
*/
public class QueryResultsMemcachedRegion extends GeneralDataMemcachedRegion implements QueryResultsRegion {
private Logger log = LoggerFactory.getLogger(QueryResultsMemcachedRegion.class);
| public QueryResultsMemcachedRegion(String regionName, OverridableReadOnlyProperties properties, Settings settings, |
kwon37xi/hibernate4-memcached | hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/regions/QueryResultsMemcachedRegion.java | // Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/memcached/CacheNamespace.java
// public class CacheNamespace implements Serializable {
// /**
// * name of region
// */
// private String name;
//
// /**
// * if this value is true, the memcached adapter should implement namespace pattern
// * or ignore namespace pattern.
// * <p/>
// * see <a href="https://code.google.com/p/memcached/wiki/NewProgrammingTricks#Namespacing">Memcached Namespacing</a>
// */
// private boolean namespaceExpirationRequired;
//
// public CacheNamespace(String name, boolean namespaceExpirationRequired) {
// this.name = name;
// this.namespaceExpirationRequired = namespaceExpirationRequired;
// }
//
// public String getName() {
// return name;
// }
//
// public boolean isNamespaceExpirationRequired() {
// return namespaceExpirationRequired;
// }
//
// @Override
// public boolean equals(Object o) {
// if (o == null) {
// return false;
// }
// if (this == o) {
// return true;
// }
// if (getClass() != o.getClass()) {
// return false;
// }
//
// CacheNamespace otherCacheNamespace = (CacheNamespace) o;
//
// return new EqualsBuilder().append(name, otherCacheNamespace.name)
// .append(namespaceExpirationRequired, otherCacheNamespace.namespaceExpirationRequired).isEquals();
// }
//
// @Override
// public int hashCode() {
// return new HashCodeBuilder().append(name).append(namespaceExpirationRequired).toHashCode();
// }
//
// @Override
// public String toString() {
// return new ToStringBuilder(this).append("name", name).append("namespaceExpirationRequired", namespaceExpirationRequired).toString();
// }
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/memcached/MemcachedAdapter.java
// public interface MemcachedAdapter {
// /**
// * Lifecycle callback to perform initialization.
// *
// * @param properties the defined cfg properties
// */
// void init(OverridableReadOnlyProperties properties);
//
// /**
// * Lifecycle callback to perform cleanup.
// */
// void destroy();
//
// /**
// * get value from memcached
// */
// Object get(CacheNamespace cacheNamespace, String key);
//
// /**
// * set value to memcache with expirySeconds
// */
// void set(CacheNamespace cacheNamespace, String key, Object value, int expirySeconds);
//
// /**
// * delete key from memcached
// */
// void delete(CacheNamespace cacheNamespace, String key);
//
// /**
// * increase given increment couter and return new value.
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param by the amount of increment
// * @param defaultValue default value when the key missing
// * @return increased value
// */
// long increaseCounter(CacheNamespace cacheNamespace, String key, long by, long defaultValue, int expirySeconds);
//
// /**
// * get current value from increment counter
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param defaultValue default value when the key missing
// * @return current value of counter without increment
// */
// long getCounter(CacheNamespace cacheNamespace, String key, long defaultValue, int expirySeconds);
//
// /**
// * Evict namespace
// *
// * @param cacheNamespace cache namespace
// */
// void evictAll(CacheNamespace cacheNamespace);
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/timestamper/HibernateCacheTimestamper.java
// public interface HibernateCacheTimestamper {
//
// void setSettings(Settings settings);
//
// void setProperties(OverridableReadOnlyProperties properties);
//
// void setMemcachedAdapter(MemcachedAdapter memcachedAdapter);
//
// /** initialize timestamp object */
// void init();
//
// /** get next timestamp */
// long next();
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/util/OverridableReadOnlyProperties.java
// public interface OverridableReadOnlyProperties {
// String getProperty(String key);
//
// String getProperty(String key, String defaultValue);
//
// String getRequiredProperty(String key);
// }
| import kr.pe.kwonnam.hibernate4memcached.memcached.CacheNamespace;
import kr.pe.kwonnam.hibernate4memcached.memcached.MemcachedAdapter;
import kr.pe.kwonnam.hibernate4memcached.timestamper.HibernateCacheTimestamper;
import kr.pe.kwonnam.hibernate4memcached.util.OverridableReadOnlyProperties;
import org.apache.commons.codec.digest.DigestUtils;
import org.hibernate.cache.spi.QueryResultsRegion;
import org.hibernate.cfg.Settings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory; | package kr.pe.kwonnam.hibernate4memcached.regions;
/**
* {@link org.hibernate.cache.spi.QueryResultsRegion}은 strategy가 없다.
*
* @author KwonNam Son ([email protected])
*/
public class QueryResultsMemcachedRegion extends GeneralDataMemcachedRegion implements QueryResultsRegion {
private Logger log = LoggerFactory.getLogger(QueryResultsMemcachedRegion.class);
public QueryResultsMemcachedRegion(String regionName, OverridableReadOnlyProperties properties, Settings settings, | // Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/memcached/CacheNamespace.java
// public class CacheNamespace implements Serializable {
// /**
// * name of region
// */
// private String name;
//
// /**
// * if this value is true, the memcached adapter should implement namespace pattern
// * or ignore namespace pattern.
// * <p/>
// * see <a href="https://code.google.com/p/memcached/wiki/NewProgrammingTricks#Namespacing">Memcached Namespacing</a>
// */
// private boolean namespaceExpirationRequired;
//
// public CacheNamespace(String name, boolean namespaceExpirationRequired) {
// this.name = name;
// this.namespaceExpirationRequired = namespaceExpirationRequired;
// }
//
// public String getName() {
// return name;
// }
//
// public boolean isNamespaceExpirationRequired() {
// return namespaceExpirationRequired;
// }
//
// @Override
// public boolean equals(Object o) {
// if (o == null) {
// return false;
// }
// if (this == o) {
// return true;
// }
// if (getClass() != o.getClass()) {
// return false;
// }
//
// CacheNamespace otherCacheNamespace = (CacheNamespace) o;
//
// return new EqualsBuilder().append(name, otherCacheNamespace.name)
// .append(namespaceExpirationRequired, otherCacheNamespace.namespaceExpirationRequired).isEquals();
// }
//
// @Override
// public int hashCode() {
// return new HashCodeBuilder().append(name).append(namespaceExpirationRequired).toHashCode();
// }
//
// @Override
// public String toString() {
// return new ToStringBuilder(this).append("name", name).append("namespaceExpirationRequired", namespaceExpirationRequired).toString();
// }
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/memcached/MemcachedAdapter.java
// public interface MemcachedAdapter {
// /**
// * Lifecycle callback to perform initialization.
// *
// * @param properties the defined cfg properties
// */
// void init(OverridableReadOnlyProperties properties);
//
// /**
// * Lifecycle callback to perform cleanup.
// */
// void destroy();
//
// /**
// * get value from memcached
// */
// Object get(CacheNamespace cacheNamespace, String key);
//
// /**
// * set value to memcache with expirySeconds
// */
// void set(CacheNamespace cacheNamespace, String key, Object value, int expirySeconds);
//
// /**
// * delete key from memcached
// */
// void delete(CacheNamespace cacheNamespace, String key);
//
// /**
// * increase given increment couter and return new value.
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param by the amount of increment
// * @param defaultValue default value when the key missing
// * @return increased value
// */
// long increaseCounter(CacheNamespace cacheNamespace, String key, long by, long defaultValue, int expirySeconds);
//
// /**
// * get current value from increment counter
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param defaultValue default value when the key missing
// * @return current value of counter without increment
// */
// long getCounter(CacheNamespace cacheNamespace, String key, long defaultValue, int expirySeconds);
//
// /**
// * Evict namespace
// *
// * @param cacheNamespace cache namespace
// */
// void evictAll(CacheNamespace cacheNamespace);
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/timestamper/HibernateCacheTimestamper.java
// public interface HibernateCacheTimestamper {
//
// void setSettings(Settings settings);
//
// void setProperties(OverridableReadOnlyProperties properties);
//
// void setMemcachedAdapter(MemcachedAdapter memcachedAdapter);
//
// /** initialize timestamp object */
// void init();
//
// /** get next timestamp */
// long next();
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/util/OverridableReadOnlyProperties.java
// public interface OverridableReadOnlyProperties {
// String getProperty(String key);
//
// String getProperty(String key, String defaultValue);
//
// String getRequiredProperty(String key);
// }
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/regions/QueryResultsMemcachedRegion.java
import kr.pe.kwonnam.hibernate4memcached.memcached.CacheNamespace;
import kr.pe.kwonnam.hibernate4memcached.memcached.MemcachedAdapter;
import kr.pe.kwonnam.hibernate4memcached.timestamper.HibernateCacheTimestamper;
import kr.pe.kwonnam.hibernate4memcached.util.OverridableReadOnlyProperties;
import org.apache.commons.codec.digest.DigestUtils;
import org.hibernate.cache.spi.QueryResultsRegion;
import org.hibernate.cfg.Settings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
package kr.pe.kwonnam.hibernate4memcached.regions;
/**
* {@link org.hibernate.cache.spi.QueryResultsRegion}은 strategy가 없다.
*
* @author KwonNam Son ([email protected])
*/
public class QueryResultsMemcachedRegion extends GeneralDataMemcachedRegion implements QueryResultsRegion {
private Logger log = LoggerFactory.getLogger(QueryResultsMemcachedRegion.class);
public QueryResultsMemcachedRegion(String regionName, OverridableReadOnlyProperties properties, Settings settings, | MemcachedAdapter memcachedAdapter, HibernateCacheTimestamper hibernateCacheTimestamper) { |
kwon37xi/hibernate4-memcached | hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/regions/QueryResultsMemcachedRegion.java | // Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/memcached/CacheNamespace.java
// public class CacheNamespace implements Serializable {
// /**
// * name of region
// */
// private String name;
//
// /**
// * if this value is true, the memcached adapter should implement namespace pattern
// * or ignore namespace pattern.
// * <p/>
// * see <a href="https://code.google.com/p/memcached/wiki/NewProgrammingTricks#Namespacing">Memcached Namespacing</a>
// */
// private boolean namespaceExpirationRequired;
//
// public CacheNamespace(String name, boolean namespaceExpirationRequired) {
// this.name = name;
// this.namespaceExpirationRequired = namespaceExpirationRequired;
// }
//
// public String getName() {
// return name;
// }
//
// public boolean isNamespaceExpirationRequired() {
// return namespaceExpirationRequired;
// }
//
// @Override
// public boolean equals(Object o) {
// if (o == null) {
// return false;
// }
// if (this == o) {
// return true;
// }
// if (getClass() != o.getClass()) {
// return false;
// }
//
// CacheNamespace otherCacheNamespace = (CacheNamespace) o;
//
// return new EqualsBuilder().append(name, otherCacheNamespace.name)
// .append(namespaceExpirationRequired, otherCacheNamespace.namespaceExpirationRequired).isEquals();
// }
//
// @Override
// public int hashCode() {
// return new HashCodeBuilder().append(name).append(namespaceExpirationRequired).toHashCode();
// }
//
// @Override
// public String toString() {
// return new ToStringBuilder(this).append("name", name).append("namespaceExpirationRequired", namespaceExpirationRequired).toString();
// }
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/memcached/MemcachedAdapter.java
// public interface MemcachedAdapter {
// /**
// * Lifecycle callback to perform initialization.
// *
// * @param properties the defined cfg properties
// */
// void init(OverridableReadOnlyProperties properties);
//
// /**
// * Lifecycle callback to perform cleanup.
// */
// void destroy();
//
// /**
// * get value from memcached
// */
// Object get(CacheNamespace cacheNamespace, String key);
//
// /**
// * set value to memcache with expirySeconds
// */
// void set(CacheNamespace cacheNamespace, String key, Object value, int expirySeconds);
//
// /**
// * delete key from memcached
// */
// void delete(CacheNamespace cacheNamespace, String key);
//
// /**
// * increase given increment couter and return new value.
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param by the amount of increment
// * @param defaultValue default value when the key missing
// * @return increased value
// */
// long increaseCounter(CacheNamespace cacheNamespace, String key, long by, long defaultValue, int expirySeconds);
//
// /**
// * get current value from increment counter
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param defaultValue default value when the key missing
// * @return current value of counter without increment
// */
// long getCounter(CacheNamespace cacheNamespace, String key, long defaultValue, int expirySeconds);
//
// /**
// * Evict namespace
// *
// * @param cacheNamespace cache namespace
// */
// void evictAll(CacheNamespace cacheNamespace);
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/timestamper/HibernateCacheTimestamper.java
// public interface HibernateCacheTimestamper {
//
// void setSettings(Settings settings);
//
// void setProperties(OverridableReadOnlyProperties properties);
//
// void setMemcachedAdapter(MemcachedAdapter memcachedAdapter);
//
// /** initialize timestamp object */
// void init();
//
// /** get next timestamp */
// long next();
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/util/OverridableReadOnlyProperties.java
// public interface OverridableReadOnlyProperties {
// String getProperty(String key);
//
// String getProperty(String key, String defaultValue);
//
// String getRequiredProperty(String key);
// }
| import kr.pe.kwonnam.hibernate4memcached.memcached.CacheNamespace;
import kr.pe.kwonnam.hibernate4memcached.memcached.MemcachedAdapter;
import kr.pe.kwonnam.hibernate4memcached.timestamper.HibernateCacheTimestamper;
import kr.pe.kwonnam.hibernate4memcached.util.OverridableReadOnlyProperties;
import org.apache.commons.codec.digest.DigestUtils;
import org.hibernate.cache.spi.QueryResultsRegion;
import org.hibernate.cfg.Settings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory; | package kr.pe.kwonnam.hibernate4memcached.regions;
/**
* {@link org.hibernate.cache.spi.QueryResultsRegion}은 strategy가 없다.
*
* @author KwonNam Son ([email protected])
*/
public class QueryResultsMemcachedRegion extends GeneralDataMemcachedRegion implements QueryResultsRegion {
private Logger log = LoggerFactory.getLogger(QueryResultsMemcachedRegion.class);
public QueryResultsMemcachedRegion(String regionName, OverridableReadOnlyProperties properties, Settings settings, | // Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/memcached/CacheNamespace.java
// public class CacheNamespace implements Serializable {
// /**
// * name of region
// */
// private String name;
//
// /**
// * if this value is true, the memcached adapter should implement namespace pattern
// * or ignore namespace pattern.
// * <p/>
// * see <a href="https://code.google.com/p/memcached/wiki/NewProgrammingTricks#Namespacing">Memcached Namespacing</a>
// */
// private boolean namespaceExpirationRequired;
//
// public CacheNamespace(String name, boolean namespaceExpirationRequired) {
// this.name = name;
// this.namespaceExpirationRequired = namespaceExpirationRequired;
// }
//
// public String getName() {
// return name;
// }
//
// public boolean isNamespaceExpirationRequired() {
// return namespaceExpirationRequired;
// }
//
// @Override
// public boolean equals(Object o) {
// if (o == null) {
// return false;
// }
// if (this == o) {
// return true;
// }
// if (getClass() != o.getClass()) {
// return false;
// }
//
// CacheNamespace otherCacheNamespace = (CacheNamespace) o;
//
// return new EqualsBuilder().append(name, otherCacheNamespace.name)
// .append(namespaceExpirationRequired, otherCacheNamespace.namespaceExpirationRequired).isEquals();
// }
//
// @Override
// public int hashCode() {
// return new HashCodeBuilder().append(name).append(namespaceExpirationRequired).toHashCode();
// }
//
// @Override
// public String toString() {
// return new ToStringBuilder(this).append("name", name).append("namespaceExpirationRequired", namespaceExpirationRequired).toString();
// }
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/memcached/MemcachedAdapter.java
// public interface MemcachedAdapter {
// /**
// * Lifecycle callback to perform initialization.
// *
// * @param properties the defined cfg properties
// */
// void init(OverridableReadOnlyProperties properties);
//
// /**
// * Lifecycle callback to perform cleanup.
// */
// void destroy();
//
// /**
// * get value from memcached
// */
// Object get(CacheNamespace cacheNamespace, String key);
//
// /**
// * set value to memcache with expirySeconds
// */
// void set(CacheNamespace cacheNamespace, String key, Object value, int expirySeconds);
//
// /**
// * delete key from memcached
// */
// void delete(CacheNamespace cacheNamespace, String key);
//
// /**
// * increase given increment couter and return new value.
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param by the amount of increment
// * @param defaultValue default value when the key missing
// * @return increased value
// */
// long increaseCounter(CacheNamespace cacheNamespace, String key, long by, long defaultValue, int expirySeconds);
//
// /**
// * get current value from increment counter
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param defaultValue default value when the key missing
// * @return current value of counter without increment
// */
// long getCounter(CacheNamespace cacheNamespace, String key, long defaultValue, int expirySeconds);
//
// /**
// * Evict namespace
// *
// * @param cacheNamespace cache namespace
// */
// void evictAll(CacheNamespace cacheNamespace);
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/timestamper/HibernateCacheTimestamper.java
// public interface HibernateCacheTimestamper {
//
// void setSettings(Settings settings);
//
// void setProperties(OverridableReadOnlyProperties properties);
//
// void setMemcachedAdapter(MemcachedAdapter memcachedAdapter);
//
// /** initialize timestamp object */
// void init();
//
// /** get next timestamp */
// long next();
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/util/OverridableReadOnlyProperties.java
// public interface OverridableReadOnlyProperties {
// String getProperty(String key);
//
// String getProperty(String key, String defaultValue);
//
// String getRequiredProperty(String key);
// }
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/regions/QueryResultsMemcachedRegion.java
import kr.pe.kwonnam.hibernate4memcached.memcached.CacheNamespace;
import kr.pe.kwonnam.hibernate4memcached.memcached.MemcachedAdapter;
import kr.pe.kwonnam.hibernate4memcached.timestamper.HibernateCacheTimestamper;
import kr.pe.kwonnam.hibernate4memcached.util.OverridableReadOnlyProperties;
import org.apache.commons.codec.digest.DigestUtils;
import org.hibernate.cache.spi.QueryResultsRegion;
import org.hibernate.cfg.Settings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
package kr.pe.kwonnam.hibernate4memcached.regions;
/**
* {@link org.hibernate.cache.spi.QueryResultsRegion}은 strategy가 없다.
*
* @author KwonNam Son ([email protected])
*/
public class QueryResultsMemcachedRegion extends GeneralDataMemcachedRegion implements QueryResultsRegion {
private Logger log = LoggerFactory.getLogger(QueryResultsMemcachedRegion.class);
public QueryResultsMemcachedRegion(String regionName, OverridableReadOnlyProperties properties, Settings settings, | MemcachedAdapter memcachedAdapter, HibernateCacheTimestamper hibernateCacheTimestamper) { |
kwon37xi/hibernate4-memcached | hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/regions/QueryResultsMemcachedRegion.java | // Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/memcached/CacheNamespace.java
// public class CacheNamespace implements Serializable {
// /**
// * name of region
// */
// private String name;
//
// /**
// * if this value is true, the memcached adapter should implement namespace pattern
// * or ignore namespace pattern.
// * <p/>
// * see <a href="https://code.google.com/p/memcached/wiki/NewProgrammingTricks#Namespacing">Memcached Namespacing</a>
// */
// private boolean namespaceExpirationRequired;
//
// public CacheNamespace(String name, boolean namespaceExpirationRequired) {
// this.name = name;
// this.namespaceExpirationRequired = namespaceExpirationRequired;
// }
//
// public String getName() {
// return name;
// }
//
// public boolean isNamespaceExpirationRequired() {
// return namespaceExpirationRequired;
// }
//
// @Override
// public boolean equals(Object o) {
// if (o == null) {
// return false;
// }
// if (this == o) {
// return true;
// }
// if (getClass() != o.getClass()) {
// return false;
// }
//
// CacheNamespace otherCacheNamespace = (CacheNamespace) o;
//
// return new EqualsBuilder().append(name, otherCacheNamespace.name)
// .append(namespaceExpirationRequired, otherCacheNamespace.namespaceExpirationRequired).isEquals();
// }
//
// @Override
// public int hashCode() {
// return new HashCodeBuilder().append(name).append(namespaceExpirationRequired).toHashCode();
// }
//
// @Override
// public String toString() {
// return new ToStringBuilder(this).append("name", name).append("namespaceExpirationRequired", namespaceExpirationRequired).toString();
// }
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/memcached/MemcachedAdapter.java
// public interface MemcachedAdapter {
// /**
// * Lifecycle callback to perform initialization.
// *
// * @param properties the defined cfg properties
// */
// void init(OverridableReadOnlyProperties properties);
//
// /**
// * Lifecycle callback to perform cleanup.
// */
// void destroy();
//
// /**
// * get value from memcached
// */
// Object get(CacheNamespace cacheNamespace, String key);
//
// /**
// * set value to memcache with expirySeconds
// */
// void set(CacheNamespace cacheNamespace, String key, Object value, int expirySeconds);
//
// /**
// * delete key from memcached
// */
// void delete(CacheNamespace cacheNamespace, String key);
//
// /**
// * increase given increment couter and return new value.
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param by the amount of increment
// * @param defaultValue default value when the key missing
// * @return increased value
// */
// long increaseCounter(CacheNamespace cacheNamespace, String key, long by, long defaultValue, int expirySeconds);
//
// /**
// * get current value from increment counter
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param defaultValue default value when the key missing
// * @return current value of counter without increment
// */
// long getCounter(CacheNamespace cacheNamespace, String key, long defaultValue, int expirySeconds);
//
// /**
// * Evict namespace
// *
// * @param cacheNamespace cache namespace
// */
// void evictAll(CacheNamespace cacheNamespace);
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/timestamper/HibernateCacheTimestamper.java
// public interface HibernateCacheTimestamper {
//
// void setSettings(Settings settings);
//
// void setProperties(OverridableReadOnlyProperties properties);
//
// void setMemcachedAdapter(MemcachedAdapter memcachedAdapter);
//
// /** initialize timestamp object */
// void init();
//
// /** get next timestamp */
// long next();
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/util/OverridableReadOnlyProperties.java
// public interface OverridableReadOnlyProperties {
// String getProperty(String key);
//
// String getProperty(String key, String defaultValue);
//
// String getRequiredProperty(String key);
// }
| import kr.pe.kwonnam.hibernate4memcached.memcached.CacheNamespace;
import kr.pe.kwonnam.hibernate4memcached.memcached.MemcachedAdapter;
import kr.pe.kwonnam.hibernate4memcached.timestamper.HibernateCacheTimestamper;
import kr.pe.kwonnam.hibernate4memcached.util.OverridableReadOnlyProperties;
import org.apache.commons.codec.digest.DigestUtils;
import org.hibernate.cache.spi.QueryResultsRegion;
import org.hibernate.cfg.Settings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory; | package kr.pe.kwonnam.hibernate4memcached.regions;
/**
* {@link org.hibernate.cache.spi.QueryResultsRegion}은 strategy가 없다.
*
* @author KwonNam Son ([email protected])
*/
public class QueryResultsMemcachedRegion extends GeneralDataMemcachedRegion implements QueryResultsRegion {
private Logger log = LoggerFactory.getLogger(QueryResultsMemcachedRegion.class);
public QueryResultsMemcachedRegion(String regionName, OverridableReadOnlyProperties properties, Settings settings,
MemcachedAdapter memcachedAdapter, HibernateCacheTimestamper hibernateCacheTimestamper) { | // Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/memcached/CacheNamespace.java
// public class CacheNamespace implements Serializable {
// /**
// * name of region
// */
// private String name;
//
// /**
// * if this value is true, the memcached adapter should implement namespace pattern
// * or ignore namespace pattern.
// * <p/>
// * see <a href="https://code.google.com/p/memcached/wiki/NewProgrammingTricks#Namespacing">Memcached Namespacing</a>
// */
// private boolean namespaceExpirationRequired;
//
// public CacheNamespace(String name, boolean namespaceExpirationRequired) {
// this.name = name;
// this.namespaceExpirationRequired = namespaceExpirationRequired;
// }
//
// public String getName() {
// return name;
// }
//
// public boolean isNamespaceExpirationRequired() {
// return namespaceExpirationRequired;
// }
//
// @Override
// public boolean equals(Object o) {
// if (o == null) {
// return false;
// }
// if (this == o) {
// return true;
// }
// if (getClass() != o.getClass()) {
// return false;
// }
//
// CacheNamespace otherCacheNamespace = (CacheNamespace) o;
//
// return new EqualsBuilder().append(name, otherCacheNamespace.name)
// .append(namespaceExpirationRequired, otherCacheNamespace.namespaceExpirationRequired).isEquals();
// }
//
// @Override
// public int hashCode() {
// return new HashCodeBuilder().append(name).append(namespaceExpirationRequired).toHashCode();
// }
//
// @Override
// public String toString() {
// return new ToStringBuilder(this).append("name", name).append("namespaceExpirationRequired", namespaceExpirationRequired).toString();
// }
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/memcached/MemcachedAdapter.java
// public interface MemcachedAdapter {
// /**
// * Lifecycle callback to perform initialization.
// *
// * @param properties the defined cfg properties
// */
// void init(OverridableReadOnlyProperties properties);
//
// /**
// * Lifecycle callback to perform cleanup.
// */
// void destroy();
//
// /**
// * get value from memcached
// */
// Object get(CacheNamespace cacheNamespace, String key);
//
// /**
// * set value to memcache with expirySeconds
// */
// void set(CacheNamespace cacheNamespace, String key, Object value, int expirySeconds);
//
// /**
// * delete key from memcached
// */
// void delete(CacheNamespace cacheNamespace, String key);
//
// /**
// * increase given increment couter and return new value.
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param by the amount of increment
// * @param defaultValue default value when the key missing
// * @return increased value
// */
// long increaseCounter(CacheNamespace cacheNamespace, String key, long by, long defaultValue, int expirySeconds);
//
// /**
// * get current value from increment counter
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param defaultValue default value when the key missing
// * @return current value of counter without increment
// */
// long getCounter(CacheNamespace cacheNamespace, String key, long defaultValue, int expirySeconds);
//
// /**
// * Evict namespace
// *
// * @param cacheNamespace cache namespace
// */
// void evictAll(CacheNamespace cacheNamespace);
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/timestamper/HibernateCacheTimestamper.java
// public interface HibernateCacheTimestamper {
//
// void setSettings(Settings settings);
//
// void setProperties(OverridableReadOnlyProperties properties);
//
// void setMemcachedAdapter(MemcachedAdapter memcachedAdapter);
//
// /** initialize timestamp object */
// void init();
//
// /** get next timestamp */
// long next();
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/util/OverridableReadOnlyProperties.java
// public interface OverridableReadOnlyProperties {
// String getProperty(String key);
//
// String getProperty(String key, String defaultValue);
//
// String getRequiredProperty(String key);
// }
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/regions/QueryResultsMemcachedRegion.java
import kr.pe.kwonnam.hibernate4memcached.memcached.CacheNamespace;
import kr.pe.kwonnam.hibernate4memcached.memcached.MemcachedAdapter;
import kr.pe.kwonnam.hibernate4memcached.timestamper.HibernateCacheTimestamper;
import kr.pe.kwonnam.hibernate4memcached.util.OverridableReadOnlyProperties;
import org.apache.commons.codec.digest.DigestUtils;
import org.hibernate.cache.spi.QueryResultsRegion;
import org.hibernate.cfg.Settings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
package kr.pe.kwonnam.hibernate4memcached.regions;
/**
* {@link org.hibernate.cache.spi.QueryResultsRegion}은 strategy가 없다.
*
* @author KwonNam Son ([email protected])
*/
public class QueryResultsMemcachedRegion extends GeneralDataMemcachedRegion implements QueryResultsRegion {
private Logger log = LoggerFactory.getLogger(QueryResultsMemcachedRegion.class);
public QueryResultsMemcachedRegion(String regionName, OverridableReadOnlyProperties properties, Settings settings,
MemcachedAdapter memcachedAdapter, HibernateCacheTimestamper hibernateCacheTimestamper) { | super(new CacheNamespace(regionName, true), properties, null, settings, memcachedAdapter, hibernateCacheTimestamper); |
kwon37xi/hibernate4-memcached | hibernate4-memcached-example/src/test/java/kr/pe/kwonnam/hibernate4memcached/example/NonstrictReadWriteSelfRelationTest.java | // Path: hibernate4-memcached-example/src/main/java/kr/pe/kwonnam/hibernate4memcached/example/entity/Employee.java
// @Entity
// @Table(name = "employees")
// @Cache(region = "employees", usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
// public class Employee implements Serializable {
// @Id
// @GeneratedValue(strategy = GenerationType.AUTO)
// private Long id;
//
// @Column(name = "name", length = 32, nullable = false)
// private String name;
//
// @Column(name = "position", length = 32, nullable = false)
// private String position;
//
// @OneToMany
// @JoinColumn(name = "boss_id", referencedColumnName = "id", nullable = true)
// @org.hibernate.annotations.OrderBy(clause = "name")
// @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
// private List<Employee> workers;
//
// public Long getId() {
// return id;
// }
//
// public void setId(Long id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public String getPosition() {
// return position;
// }
//
// public void setPosition(String position) {
// this.position = position;
// }
//
// public List<Employee> getWorkers() {
// return workers;
// }
//
// public void setWorkers(List<Employee> workers) {
// this.workers = workers;
// }
//
// public void addWorker(Employee worker) {
// if (workers == null) {
// workers = new ArrayList<Employee>();
// }
//
// workers.add(worker);
// }
//
// @Override
// public String toString() {
// return "Employee{" +
// "id=" + id +
// ", name='" + name + '\'' +
// ", position='" + position + '\'' +
// ", workers=" + workers +
// '}';
// }
// }
| import kr.pe.kwonnam.hibernate4memcached.example.entity.Employee;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
import static org.fest.assertions.api.Assertions.assertThat; | package kr.pe.kwonnam.hibernate4memcached.example;
/**
* @author KwonNam Son ([email protected])
*/
public class NonstrictReadWriteSelfRelationTest {
private Logger log = LoggerFactory.getLogger(NonstrictReadWriteSelfRelationTest.class);
@Before
public void setUp() throws Exception {
EntityTestUtils.init();
}
@After
public void tearDown() throws Exception {
EntityTestUtils.destroy();
}
@Test
public void selfRelation() throws Exception {
log.debug("#### Load data");
EntityManager em = EntityTestUtils.start();
EntityTransaction transaction = em.getTransaction();
transaction.begin();
| // Path: hibernate4-memcached-example/src/main/java/kr/pe/kwonnam/hibernate4memcached/example/entity/Employee.java
// @Entity
// @Table(name = "employees")
// @Cache(region = "employees", usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
// public class Employee implements Serializable {
// @Id
// @GeneratedValue(strategy = GenerationType.AUTO)
// private Long id;
//
// @Column(name = "name", length = 32, nullable = false)
// private String name;
//
// @Column(name = "position", length = 32, nullable = false)
// private String position;
//
// @OneToMany
// @JoinColumn(name = "boss_id", referencedColumnName = "id", nullable = true)
// @org.hibernate.annotations.OrderBy(clause = "name")
// @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
// private List<Employee> workers;
//
// public Long getId() {
// return id;
// }
//
// public void setId(Long id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public String getPosition() {
// return position;
// }
//
// public void setPosition(String position) {
// this.position = position;
// }
//
// public List<Employee> getWorkers() {
// return workers;
// }
//
// public void setWorkers(List<Employee> workers) {
// this.workers = workers;
// }
//
// public void addWorker(Employee worker) {
// if (workers == null) {
// workers = new ArrayList<Employee>();
// }
//
// workers.add(worker);
// }
//
// @Override
// public String toString() {
// return "Employee{" +
// "id=" + id +
// ", name='" + name + '\'' +
// ", position='" + position + '\'' +
// ", workers=" + workers +
// '}';
// }
// }
// Path: hibernate4-memcached-example/src/test/java/kr/pe/kwonnam/hibernate4memcached/example/NonstrictReadWriteSelfRelationTest.java
import kr.pe.kwonnam.hibernate4memcached.example.entity.Employee;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
import static org.fest.assertions.api.Assertions.assertThat;
package kr.pe.kwonnam.hibernate4memcached.example;
/**
* @author KwonNam Son ([email protected])
*/
public class NonstrictReadWriteSelfRelationTest {
private Logger log = LoggerFactory.getLogger(NonstrictReadWriteSelfRelationTest.class);
@Before
public void setUp() throws Exception {
EntityTestUtils.init();
}
@After
public void tearDown() throws Exception {
EntityTestUtils.destroy();
}
@Test
public void selfRelation() throws Exception {
log.debug("#### Load data");
EntityManager em = EntityTestUtils.start();
EntityTransaction transaction = em.getTransaction();
transaction.begin();
| Employee boss = new Employee(); |
kwon37xi/hibernate4-memcached | hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/timestamper/HibernateCacheTimestamper.java | // Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/memcached/MemcachedAdapter.java
// public interface MemcachedAdapter {
// /**
// * Lifecycle callback to perform initialization.
// *
// * @param properties the defined cfg properties
// */
// void init(OverridableReadOnlyProperties properties);
//
// /**
// * Lifecycle callback to perform cleanup.
// */
// void destroy();
//
// /**
// * get value from memcached
// */
// Object get(CacheNamespace cacheNamespace, String key);
//
// /**
// * set value to memcache with expirySeconds
// */
// void set(CacheNamespace cacheNamespace, String key, Object value, int expirySeconds);
//
// /**
// * delete key from memcached
// */
// void delete(CacheNamespace cacheNamespace, String key);
//
// /**
// * increase given increment couter and return new value.
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param by the amount of increment
// * @param defaultValue default value when the key missing
// * @return increased value
// */
// long increaseCounter(CacheNamespace cacheNamespace, String key, long by, long defaultValue, int expirySeconds);
//
// /**
// * get current value from increment counter
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param defaultValue default value when the key missing
// * @return current value of counter without increment
// */
// long getCounter(CacheNamespace cacheNamespace, String key, long defaultValue, int expirySeconds);
//
// /**
// * Evict namespace
// *
// * @param cacheNamespace cache namespace
// */
// void evictAll(CacheNamespace cacheNamespace);
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/util/OverridableReadOnlyProperties.java
// public interface OverridableReadOnlyProperties {
// String getProperty(String key);
//
// String getProperty(String key, String defaultValue);
//
// String getRequiredProperty(String key);
// }
| import kr.pe.kwonnam.hibernate4memcached.memcached.MemcachedAdapter;
import kr.pe.kwonnam.hibernate4memcached.util.OverridableReadOnlyProperties;
import org.hibernate.cfg.Settings; | package kr.pe.kwonnam.hibernate4memcached.timestamper;
/**
* @author KwonNam Son ([email protected])
*/
public interface HibernateCacheTimestamper {
void setSettings(Settings settings);
| // Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/memcached/MemcachedAdapter.java
// public interface MemcachedAdapter {
// /**
// * Lifecycle callback to perform initialization.
// *
// * @param properties the defined cfg properties
// */
// void init(OverridableReadOnlyProperties properties);
//
// /**
// * Lifecycle callback to perform cleanup.
// */
// void destroy();
//
// /**
// * get value from memcached
// */
// Object get(CacheNamespace cacheNamespace, String key);
//
// /**
// * set value to memcache with expirySeconds
// */
// void set(CacheNamespace cacheNamespace, String key, Object value, int expirySeconds);
//
// /**
// * delete key from memcached
// */
// void delete(CacheNamespace cacheNamespace, String key);
//
// /**
// * increase given increment couter and return new value.
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param by the amount of increment
// * @param defaultValue default value when the key missing
// * @return increased value
// */
// long increaseCounter(CacheNamespace cacheNamespace, String key, long by, long defaultValue, int expirySeconds);
//
// /**
// * get current value from increment counter
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param defaultValue default value when the key missing
// * @return current value of counter without increment
// */
// long getCounter(CacheNamespace cacheNamespace, String key, long defaultValue, int expirySeconds);
//
// /**
// * Evict namespace
// *
// * @param cacheNamespace cache namespace
// */
// void evictAll(CacheNamespace cacheNamespace);
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/util/OverridableReadOnlyProperties.java
// public interface OverridableReadOnlyProperties {
// String getProperty(String key);
//
// String getProperty(String key, String defaultValue);
//
// String getRequiredProperty(String key);
// }
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/timestamper/HibernateCacheTimestamper.java
import kr.pe.kwonnam.hibernate4memcached.memcached.MemcachedAdapter;
import kr.pe.kwonnam.hibernate4memcached.util.OverridableReadOnlyProperties;
import org.hibernate.cfg.Settings;
package kr.pe.kwonnam.hibernate4memcached.timestamper;
/**
* @author KwonNam Son ([email protected])
*/
public interface HibernateCacheTimestamper {
void setSettings(Settings settings);
| void setProperties(OverridableReadOnlyProperties properties); |
kwon37xi/hibernate4-memcached | hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/timestamper/HibernateCacheTimestamper.java | // Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/memcached/MemcachedAdapter.java
// public interface MemcachedAdapter {
// /**
// * Lifecycle callback to perform initialization.
// *
// * @param properties the defined cfg properties
// */
// void init(OverridableReadOnlyProperties properties);
//
// /**
// * Lifecycle callback to perform cleanup.
// */
// void destroy();
//
// /**
// * get value from memcached
// */
// Object get(CacheNamespace cacheNamespace, String key);
//
// /**
// * set value to memcache with expirySeconds
// */
// void set(CacheNamespace cacheNamespace, String key, Object value, int expirySeconds);
//
// /**
// * delete key from memcached
// */
// void delete(CacheNamespace cacheNamespace, String key);
//
// /**
// * increase given increment couter and return new value.
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param by the amount of increment
// * @param defaultValue default value when the key missing
// * @return increased value
// */
// long increaseCounter(CacheNamespace cacheNamespace, String key, long by, long defaultValue, int expirySeconds);
//
// /**
// * get current value from increment counter
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param defaultValue default value when the key missing
// * @return current value of counter without increment
// */
// long getCounter(CacheNamespace cacheNamespace, String key, long defaultValue, int expirySeconds);
//
// /**
// * Evict namespace
// *
// * @param cacheNamespace cache namespace
// */
// void evictAll(CacheNamespace cacheNamespace);
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/util/OverridableReadOnlyProperties.java
// public interface OverridableReadOnlyProperties {
// String getProperty(String key);
//
// String getProperty(String key, String defaultValue);
//
// String getRequiredProperty(String key);
// }
| import kr.pe.kwonnam.hibernate4memcached.memcached.MemcachedAdapter;
import kr.pe.kwonnam.hibernate4memcached.util.OverridableReadOnlyProperties;
import org.hibernate.cfg.Settings; | package kr.pe.kwonnam.hibernate4memcached.timestamper;
/**
* @author KwonNam Son ([email protected])
*/
public interface HibernateCacheTimestamper {
void setSettings(Settings settings);
void setProperties(OverridableReadOnlyProperties properties);
| // Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/memcached/MemcachedAdapter.java
// public interface MemcachedAdapter {
// /**
// * Lifecycle callback to perform initialization.
// *
// * @param properties the defined cfg properties
// */
// void init(OverridableReadOnlyProperties properties);
//
// /**
// * Lifecycle callback to perform cleanup.
// */
// void destroy();
//
// /**
// * get value from memcached
// */
// Object get(CacheNamespace cacheNamespace, String key);
//
// /**
// * set value to memcache with expirySeconds
// */
// void set(CacheNamespace cacheNamespace, String key, Object value, int expirySeconds);
//
// /**
// * delete key from memcached
// */
// void delete(CacheNamespace cacheNamespace, String key);
//
// /**
// * increase given increment couter and return new value.
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param by the amount of increment
// * @param defaultValue default value when the key missing
// * @return increased value
// */
// long increaseCounter(CacheNamespace cacheNamespace, String key, long by, long defaultValue, int expirySeconds);
//
// /**
// * get current value from increment counter
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param defaultValue default value when the key missing
// * @return current value of counter without increment
// */
// long getCounter(CacheNamespace cacheNamespace, String key, long defaultValue, int expirySeconds);
//
// /**
// * Evict namespace
// *
// * @param cacheNamespace cache namespace
// */
// void evictAll(CacheNamespace cacheNamespace);
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/util/OverridableReadOnlyProperties.java
// public interface OverridableReadOnlyProperties {
// String getProperty(String key);
//
// String getProperty(String key, String defaultValue);
//
// String getRequiredProperty(String key);
// }
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/timestamper/HibernateCacheTimestamper.java
import kr.pe.kwonnam.hibernate4memcached.memcached.MemcachedAdapter;
import kr.pe.kwonnam.hibernate4memcached.util.OverridableReadOnlyProperties;
import org.hibernate.cfg.Settings;
package kr.pe.kwonnam.hibernate4memcached.timestamper;
/**
* @author KwonNam Son ([email protected])
*/
public interface HibernateCacheTimestamper {
void setSettings(Settings settings);
void setProperties(OverridableReadOnlyProperties properties);
| void setMemcachedAdapter(MemcachedAdapter memcachedAdapter); |
kwon37xi/hibernate4-memcached | hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/strategies/ReadOnlyEntityRegionAccessStrategy.java | // Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/regions/EntityMemcachedRegion.java
// public class EntityMemcachedRegion extends TransactionalDataMemcachedRegion implements EntityRegion {
// public EntityMemcachedRegion(String regionName, OverridableReadOnlyProperties properties, CacheDataDescription metadata, Settings settings, MemcachedAdapter memcachedAdapter, HibernateCacheTimestamper hibernateCacheTimestamper) {
// super(new CacheNamespace(regionName, true), properties, metadata, settings, memcachedAdapter, hibernateCacheTimestamper);
// }
//
// @Override
// public EntityRegionAccessStrategy buildAccessStrategy(AccessType accessType) throws CacheException {
// switch (accessType) {
// case READ_ONLY:
// return new ReadOnlyEntityRegionAccessStrategy(this);
// case NONSTRICT_READ_WRITE:
// return new NonstrictReadWriteEntityRegionAccessStrategy(this);
// default:
// throw new CacheException("Unsupported access strategy : " + accessType + ".");
// }
// }
// }
| import kr.pe.kwonnam.hibernate4memcached.regions.EntityMemcachedRegion;
import org.hibernate.cache.CacheException;
import org.hibernate.cache.spi.access.SoftLock;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory; | package kr.pe.kwonnam.hibernate4memcached.strategies;
/**
* ReadOnly concurrency strategy.
*
* @author KwonNam Son ([email protected])
* @see org.hibernate.cache.spi.access.EntityRegionAccessStrategy
*/
public class ReadOnlyEntityRegionAccessStrategy extends BaseEntityMemcachedRegionAccessStrategy {
private Logger log = LoggerFactory.getLogger(ReadOnlyEntityRegionAccessStrategy.class);
| // Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/regions/EntityMemcachedRegion.java
// public class EntityMemcachedRegion extends TransactionalDataMemcachedRegion implements EntityRegion {
// public EntityMemcachedRegion(String regionName, OverridableReadOnlyProperties properties, CacheDataDescription metadata, Settings settings, MemcachedAdapter memcachedAdapter, HibernateCacheTimestamper hibernateCacheTimestamper) {
// super(new CacheNamespace(regionName, true), properties, metadata, settings, memcachedAdapter, hibernateCacheTimestamper);
// }
//
// @Override
// public EntityRegionAccessStrategy buildAccessStrategy(AccessType accessType) throws CacheException {
// switch (accessType) {
// case READ_ONLY:
// return new ReadOnlyEntityRegionAccessStrategy(this);
// case NONSTRICT_READ_WRITE:
// return new NonstrictReadWriteEntityRegionAccessStrategy(this);
// default:
// throw new CacheException("Unsupported access strategy : " + accessType + ".");
// }
// }
// }
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/strategies/ReadOnlyEntityRegionAccessStrategy.java
import kr.pe.kwonnam.hibernate4memcached.regions.EntityMemcachedRegion;
import org.hibernate.cache.CacheException;
import org.hibernate.cache.spi.access.SoftLock;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
package kr.pe.kwonnam.hibernate4memcached.strategies;
/**
* ReadOnly concurrency strategy.
*
* @author KwonNam Son ([email protected])
* @see org.hibernate.cache.spi.access.EntityRegionAccessStrategy
*/
public class ReadOnlyEntityRegionAccessStrategy extends BaseEntityMemcachedRegionAccessStrategy {
private Logger log = LoggerFactory.getLogger(ReadOnlyEntityRegionAccessStrategy.class);
| public ReadOnlyEntityRegionAccessStrategy(EntityMemcachedRegion entityMemcachedRegion) { |
kwon37xi/hibernate4-memcached | hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/timestamper/HibernateCacheTimestamperJvmImpl.java | // Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/memcached/MemcachedAdapter.java
// public interface MemcachedAdapter {
// /**
// * Lifecycle callback to perform initialization.
// *
// * @param properties the defined cfg properties
// */
// void init(OverridableReadOnlyProperties properties);
//
// /**
// * Lifecycle callback to perform cleanup.
// */
// void destroy();
//
// /**
// * get value from memcached
// */
// Object get(CacheNamespace cacheNamespace, String key);
//
// /**
// * set value to memcache with expirySeconds
// */
// void set(CacheNamespace cacheNamespace, String key, Object value, int expirySeconds);
//
// /**
// * delete key from memcached
// */
// void delete(CacheNamespace cacheNamespace, String key);
//
// /**
// * increase given increment couter and return new value.
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param by the amount of increment
// * @param defaultValue default value when the key missing
// * @return increased value
// */
// long increaseCounter(CacheNamespace cacheNamespace, String key, long by, long defaultValue, int expirySeconds);
//
// /**
// * get current value from increment counter
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param defaultValue default value when the key missing
// * @return current value of counter without increment
// */
// long getCounter(CacheNamespace cacheNamespace, String key, long defaultValue, int expirySeconds);
//
// /**
// * Evict namespace
// *
// * @param cacheNamespace cache namespace
// */
// void evictAll(CacheNamespace cacheNamespace);
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/util/OverridableReadOnlyProperties.java
// public interface OverridableReadOnlyProperties {
// String getProperty(String key);
//
// String getProperty(String key, String defaultValue);
//
// String getRequiredProperty(String key);
// }
| import kr.pe.kwonnam.hibernate4memcached.memcached.MemcachedAdapter;
import kr.pe.kwonnam.hibernate4memcached.util.OverridableReadOnlyProperties;
import org.hibernate.cfg.Settings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory; | package kr.pe.kwonnam.hibernate4memcached.timestamper;
/**
* next timestamp based System.currentTimeMillis
* <p/>
* If strictly increasing timestamp required, use {@link HibernateCacheTimestamperMemcachedImpl}.
*
* @author KwonNam Son ([email protected])
*/
public class HibernateCacheTimestamperJvmImpl implements HibernateCacheTimestamper {
private Logger log = LoggerFactory.getLogger(HibernateCacheTimestamperJvmImpl.class);
@Override
public void setSettings(Settings settings) {
// no op
}
@Override | // Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/memcached/MemcachedAdapter.java
// public interface MemcachedAdapter {
// /**
// * Lifecycle callback to perform initialization.
// *
// * @param properties the defined cfg properties
// */
// void init(OverridableReadOnlyProperties properties);
//
// /**
// * Lifecycle callback to perform cleanup.
// */
// void destroy();
//
// /**
// * get value from memcached
// */
// Object get(CacheNamespace cacheNamespace, String key);
//
// /**
// * set value to memcache with expirySeconds
// */
// void set(CacheNamespace cacheNamespace, String key, Object value, int expirySeconds);
//
// /**
// * delete key from memcached
// */
// void delete(CacheNamespace cacheNamespace, String key);
//
// /**
// * increase given increment couter and return new value.
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param by the amount of increment
// * @param defaultValue default value when the key missing
// * @return increased value
// */
// long increaseCounter(CacheNamespace cacheNamespace, String key, long by, long defaultValue, int expirySeconds);
//
// /**
// * get current value from increment counter
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param defaultValue default value when the key missing
// * @return current value of counter without increment
// */
// long getCounter(CacheNamespace cacheNamespace, String key, long defaultValue, int expirySeconds);
//
// /**
// * Evict namespace
// *
// * @param cacheNamespace cache namespace
// */
// void evictAll(CacheNamespace cacheNamespace);
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/util/OverridableReadOnlyProperties.java
// public interface OverridableReadOnlyProperties {
// String getProperty(String key);
//
// String getProperty(String key, String defaultValue);
//
// String getRequiredProperty(String key);
// }
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/timestamper/HibernateCacheTimestamperJvmImpl.java
import kr.pe.kwonnam.hibernate4memcached.memcached.MemcachedAdapter;
import kr.pe.kwonnam.hibernate4memcached.util.OverridableReadOnlyProperties;
import org.hibernate.cfg.Settings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
package kr.pe.kwonnam.hibernate4memcached.timestamper;
/**
* next timestamp based System.currentTimeMillis
* <p/>
* If strictly increasing timestamp required, use {@link HibernateCacheTimestamperMemcachedImpl}.
*
* @author KwonNam Son ([email protected])
*/
public class HibernateCacheTimestamperJvmImpl implements HibernateCacheTimestamper {
private Logger log = LoggerFactory.getLogger(HibernateCacheTimestamperJvmImpl.class);
@Override
public void setSettings(Settings settings) {
// no op
}
@Override | public void setProperties(OverridableReadOnlyProperties properties) { |
kwon37xi/hibernate4-memcached | hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/timestamper/HibernateCacheTimestamperJvmImpl.java | // Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/memcached/MemcachedAdapter.java
// public interface MemcachedAdapter {
// /**
// * Lifecycle callback to perform initialization.
// *
// * @param properties the defined cfg properties
// */
// void init(OverridableReadOnlyProperties properties);
//
// /**
// * Lifecycle callback to perform cleanup.
// */
// void destroy();
//
// /**
// * get value from memcached
// */
// Object get(CacheNamespace cacheNamespace, String key);
//
// /**
// * set value to memcache with expirySeconds
// */
// void set(CacheNamespace cacheNamespace, String key, Object value, int expirySeconds);
//
// /**
// * delete key from memcached
// */
// void delete(CacheNamespace cacheNamespace, String key);
//
// /**
// * increase given increment couter and return new value.
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param by the amount of increment
// * @param defaultValue default value when the key missing
// * @return increased value
// */
// long increaseCounter(CacheNamespace cacheNamespace, String key, long by, long defaultValue, int expirySeconds);
//
// /**
// * get current value from increment counter
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param defaultValue default value when the key missing
// * @return current value of counter without increment
// */
// long getCounter(CacheNamespace cacheNamespace, String key, long defaultValue, int expirySeconds);
//
// /**
// * Evict namespace
// *
// * @param cacheNamespace cache namespace
// */
// void evictAll(CacheNamespace cacheNamespace);
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/util/OverridableReadOnlyProperties.java
// public interface OverridableReadOnlyProperties {
// String getProperty(String key);
//
// String getProperty(String key, String defaultValue);
//
// String getRequiredProperty(String key);
// }
| import kr.pe.kwonnam.hibernate4memcached.memcached.MemcachedAdapter;
import kr.pe.kwonnam.hibernate4memcached.util.OverridableReadOnlyProperties;
import org.hibernate.cfg.Settings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory; | package kr.pe.kwonnam.hibernate4memcached.timestamper;
/**
* next timestamp based System.currentTimeMillis
* <p/>
* If strictly increasing timestamp required, use {@link HibernateCacheTimestamperMemcachedImpl}.
*
* @author KwonNam Son ([email protected])
*/
public class HibernateCacheTimestamperJvmImpl implements HibernateCacheTimestamper {
private Logger log = LoggerFactory.getLogger(HibernateCacheTimestamperJvmImpl.class);
@Override
public void setSettings(Settings settings) {
// no op
}
@Override
public void setProperties(OverridableReadOnlyProperties properties) {
// no op
}
@Override | // Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/memcached/MemcachedAdapter.java
// public interface MemcachedAdapter {
// /**
// * Lifecycle callback to perform initialization.
// *
// * @param properties the defined cfg properties
// */
// void init(OverridableReadOnlyProperties properties);
//
// /**
// * Lifecycle callback to perform cleanup.
// */
// void destroy();
//
// /**
// * get value from memcached
// */
// Object get(CacheNamespace cacheNamespace, String key);
//
// /**
// * set value to memcache with expirySeconds
// */
// void set(CacheNamespace cacheNamespace, String key, Object value, int expirySeconds);
//
// /**
// * delete key from memcached
// */
// void delete(CacheNamespace cacheNamespace, String key);
//
// /**
// * increase given increment couter and return new value.
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param by the amount of increment
// * @param defaultValue default value when the key missing
// * @return increased value
// */
// long increaseCounter(CacheNamespace cacheNamespace, String key, long by, long defaultValue, int expirySeconds);
//
// /**
// * get current value from increment counter
// *
// * @param cacheNamespace cache namespace
// * @param key counter key
// * @param defaultValue default value when the key missing
// * @return current value of counter without increment
// */
// long getCounter(CacheNamespace cacheNamespace, String key, long defaultValue, int expirySeconds);
//
// /**
// * Evict namespace
// *
// * @param cacheNamespace cache namespace
// */
// void evictAll(CacheNamespace cacheNamespace);
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/util/OverridableReadOnlyProperties.java
// public interface OverridableReadOnlyProperties {
// String getProperty(String key);
//
// String getProperty(String key, String defaultValue);
//
// String getRequiredProperty(String key);
// }
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/timestamper/HibernateCacheTimestamperJvmImpl.java
import kr.pe.kwonnam.hibernate4memcached.memcached.MemcachedAdapter;
import kr.pe.kwonnam.hibernate4memcached.util.OverridableReadOnlyProperties;
import org.hibernate.cfg.Settings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
package kr.pe.kwonnam.hibernate4memcached.timestamper;
/**
* next timestamp based System.currentTimeMillis
* <p/>
* If strictly increasing timestamp required, use {@link HibernateCacheTimestamperMemcachedImpl}.
*
* @author KwonNam Son ([email protected])
*/
public class HibernateCacheTimestamperJvmImpl implements HibernateCacheTimestamper {
private Logger log = LoggerFactory.getLogger(HibernateCacheTimestamperJvmImpl.class);
@Override
public void setSettings(Settings settings) {
// no op
}
@Override
public void setProperties(OverridableReadOnlyProperties properties) {
// no op
}
@Override | public void setMemcachedAdapter(MemcachedAdapter memcachedAdapter) { |
kwon37xi/hibernate4-memcached | hibernate4-memcached-spymemcached-adapter/src/test/java/kr/pe/kwonnam/hibernate4memcached/spymemcached/KryoTranscoderTest.java | // Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/util/OverridableReadOnlyProperties.java
// public interface OverridableReadOnlyProperties {
// String getProperty(String key);
//
// String getProperty(String key, String defaultValue);
//
// String getRequiredProperty(String key);
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/util/OverridableReadOnlyPropertiesImpl.java
// public class OverridableReadOnlyPropertiesImpl implements OverridableReadOnlyProperties {
//
// private List<Properties> propertieses;
//
// public OverridableReadOnlyPropertiesImpl(Properties... propertieses) {
// this(Arrays.asList(propertieses));
// }
//
// public OverridableReadOnlyPropertiesImpl(List<Properties> propertieses) {
// if (propertieses == null || propertieses.size() == 0) {
// throw new IllegalArgumentException("propertieses can not be null.");
// }
//
// if (propertieses.contains(null)) {
// throw new IllegalArgumentException("propertieses can not contain null properties");
// }
//
// this.propertieses = propertieses;
// }
//
// @Override
// public String getProperty(String key) {
// return getProperty(key, null);
// }
//
// @Override
// public String getProperty(String key, String defaultValue) {
// int size = propertieses.size();
// for (int i = size - 1; i >= 0; i--) {
// Properties properties = propertieses.get(i);
//
// String value = properties.getProperty(key);
// if (value != null) {
// return value;
// }
// }
// return defaultValue;
// }
//
// @Override
// public String getRequiredProperty(String key) {
// String value = getProperty(key);
// if (value == null) {
// throw new IllegalStateException(key + " property is required!");
// }
// return value;
// }
// }
| import kr.pe.kwonnam.hibernate4memcached.util.OverridableReadOnlyProperties;
import kr.pe.kwonnam.hibernate4memcached.util.OverridableReadOnlyPropertiesImpl;
import net.spy.memcached.CachedData;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.nio.charset.Charset;
import java.util.Properties;
import static org.fest.assertions.api.Assertions.assertThat; | package kr.pe.kwonnam.hibernate4memcached.spymemcached;
public class KryoTranscoderTest {
private Logger log = LoggerFactory.getLogger(KryoTranscoderTest.class);
@Rule
public ExpectedException expectedException = ExpectedException.none();
private KryoTranscoder kryoTranscoder;
private void givenKryoTranscoder(int compressionThreadHold) {
Properties properties = new Properties();
properties.setProperty(KryoTranscoder.COMPRESSION_THREASHOLD_PROPERTY_KEY, String.valueOf(compressionThreadHold));
kryoTranscoder = new KryoTranscoder(); | // Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/util/OverridableReadOnlyProperties.java
// public interface OverridableReadOnlyProperties {
// String getProperty(String key);
//
// String getProperty(String key, String defaultValue);
//
// String getRequiredProperty(String key);
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/util/OverridableReadOnlyPropertiesImpl.java
// public class OverridableReadOnlyPropertiesImpl implements OverridableReadOnlyProperties {
//
// private List<Properties> propertieses;
//
// public OverridableReadOnlyPropertiesImpl(Properties... propertieses) {
// this(Arrays.asList(propertieses));
// }
//
// public OverridableReadOnlyPropertiesImpl(List<Properties> propertieses) {
// if (propertieses == null || propertieses.size() == 0) {
// throw new IllegalArgumentException("propertieses can not be null.");
// }
//
// if (propertieses.contains(null)) {
// throw new IllegalArgumentException("propertieses can not contain null properties");
// }
//
// this.propertieses = propertieses;
// }
//
// @Override
// public String getProperty(String key) {
// return getProperty(key, null);
// }
//
// @Override
// public String getProperty(String key, String defaultValue) {
// int size = propertieses.size();
// for (int i = size - 1; i >= 0; i--) {
// Properties properties = propertieses.get(i);
//
// String value = properties.getProperty(key);
// if (value != null) {
// return value;
// }
// }
// return defaultValue;
// }
//
// @Override
// public String getRequiredProperty(String key) {
// String value = getProperty(key);
// if (value == null) {
// throw new IllegalStateException(key + " property is required!");
// }
// return value;
// }
// }
// Path: hibernate4-memcached-spymemcached-adapter/src/test/java/kr/pe/kwonnam/hibernate4memcached/spymemcached/KryoTranscoderTest.java
import kr.pe.kwonnam.hibernate4memcached.util.OverridableReadOnlyProperties;
import kr.pe.kwonnam.hibernate4memcached.util.OverridableReadOnlyPropertiesImpl;
import net.spy.memcached.CachedData;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.nio.charset.Charset;
import java.util.Properties;
import static org.fest.assertions.api.Assertions.assertThat;
package kr.pe.kwonnam.hibernate4memcached.spymemcached;
public class KryoTranscoderTest {
private Logger log = LoggerFactory.getLogger(KryoTranscoderTest.class);
@Rule
public ExpectedException expectedException = ExpectedException.none();
private KryoTranscoder kryoTranscoder;
private void givenKryoTranscoder(int compressionThreadHold) {
Properties properties = new Properties();
properties.setProperty(KryoTranscoder.COMPRESSION_THREASHOLD_PROPERTY_KEY, String.valueOf(compressionThreadHold));
kryoTranscoder = new KryoTranscoder(); | kryoTranscoder.init(new OverridableReadOnlyPropertiesImpl(properties)); |
kwon37xi/hibernate4-memcached | hibernate4-memcached-example/src/test/java/kr/pe/kwonnam/hibernate4memcached/example/ReadOnlyTest.java | // Path: hibernate4-memcached-example/src/main/java/kr/pe/kwonnam/hibernate4memcached/example/entity/Person.java
// @Entity
// @Table(name = "people")
// @Cache(usage = CacheConcurrencyStrategy.READ_ONLY, region = "people")
// public class Person implements Serializable {
// @Id
// @GeneratedValue(strategy = GenerationType.AUTO)
// @Column(name = "person_id", nullable = false)
// private long id;
//
// @Column(name = "name", length = 32, nullable = false)
// private String name;
//
// @Column(name="birthdate", nullable = true)
// @Temporal(TemporalType.DATE)
// private Date birthdate;
//
// public long getId() {
// return id;
// }
//
// public void setId(long id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public Date getBirthdate() {
// return birthdate;
// }
//
// public void setBirthdate(Date birthdate) {
// this.birthdate = birthdate;
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) return true;
// if (o == null || getClass() != o.getClass()) return false;
//
// Person person = (Person) o;
//
// if (id != person.id) return false;
//
// return true;
// }
//
// @Override
// public int hashCode() {
// return (int) (id ^ (id >>> 32));
// }
//
// @Override
// public String toString() {
// return "Person{" +
// "id='" + id + '\'' +
// ", name='" + name + '\'' +
// ", birthdate=" + birthdate +
// '}';
// }
// }
| import kr.pe.kwonnam.hibernate4memcached.example.entity.Person;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
import javax.persistence.Query;
import java.util.Date; | package kr.pe.kwonnam.hibernate4memcached.example;
/**
* @author KwonNam Son ([email protected])
*/
public class ReadOnlyTest {
private Logger log = LoggerFactory.getLogger(ReadOnlyTest.class);
@Before
public void setUp() throws Exception {
EntityTestUtils.init();
}
@Test
public void readonly() throws Exception {
EntityManager em = EntityTestUtils.start();
EntityTransaction transaction = em.getTransaction();
transaction.begin();
log.debug("### First load and save");
log.debug("person 1 first load."); | // Path: hibernate4-memcached-example/src/main/java/kr/pe/kwonnam/hibernate4memcached/example/entity/Person.java
// @Entity
// @Table(name = "people")
// @Cache(usage = CacheConcurrencyStrategy.READ_ONLY, region = "people")
// public class Person implements Serializable {
// @Id
// @GeneratedValue(strategy = GenerationType.AUTO)
// @Column(name = "person_id", nullable = false)
// private long id;
//
// @Column(name = "name", length = 32, nullable = false)
// private String name;
//
// @Column(name="birthdate", nullable = true)
// @Temporal(TemporalType.DATE)
// private Date birthdate;
//
// public long getId() {
// return id;
// }
//
// public void setId(long id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public Date getBirthdate() {
// return birthdate;
// }
//
// public void setBirthdate(Date birthdate) {
// this.birthdate = birthdate;
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) return true;
// if (o == null || getClass() != o.getClass()) return false;
//
// Person person = (Person) o;
//
// if (id != person.id) return false;
//
// return true;
// }
//
// @Override
// public int hashCode() {
// return (int) (id ^ (id >>> 32));
// }
//
// @Override
// public String toString() {
// return "Person{" +
// "id='" + id + '\'' +
// ", name='" + name + '\'' +
// ", birthdate=" + birthdate +
// '}';
// }
// }
// Path: hibernate4-memcached-example/src/test/java/kr/pe/kwonnam/hibernate4memcached/example/ReadOnlyTest.java
import kr.pe.kwonnam.hibernate4memcached.example.entity.Person;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
import javax.persistence.Query;
import java.util.Date;
package kr.pe.kwonnam.hibernate4memcached.example;
/**
* @author KwonNam Son ([email protected])
*/
public class ReadOnlyTest {
private Logger log = LoggerFactory.getLogger(ReadOnlyTest.class);
@Before
public void setUp() throws Exception {
EntityTestUtils.init();
}
@Test
public void readonly() throws Exception {
EntityManager em = EntityTestUtils.start();
EntityTransaction transaction = em.getTransaction();
transaction.begin();
log.debug("### First load and save");
log.debug("person 1 first load."); | Person person = em.find(Person.class, 1L); |
kwon37xi/hibernate4-memcached | hibernate4-memcached-core/src/test/java/kr/pe/kwonnam/hibernate4memcached/strategies/NonstrictReadWriteEntityRegionAccessStrategyTest.java | // Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/regions/EntityMemcachedRegion.java
// public class EntityMemcachedRegion extends TransactionalDataMemcachedRegion implements EntityRegion {
// public EntityMemcachedRegion(String regionName, OverridableReadOnlyProperties properties, CacheDataDescription metadata, Settings settings, MemcachedAdapter memcachedAdapter, HibernateCacheTimestamper hibernateCacheTimestamper) {
// super(new CacheNamespace(regionName, true), properties, metadata, settings, memcachedAdapter, hibernateCacheTimestamper);
// }
//
// @Override
// public EntityRegionAccessStrategy buildAccessStrategy(AccessType accessType) throws CacheException {
// switch (accessType) {
// case READ_ONLY:
// return new ReadOnlyEntityRegionAccessStrategy(this);
// case NONSTRICT_READ_WRITE:
// return new NonstrictReadWriteEntityRegionAccessStrategy(this);
// default:
// throw new CacheException("Unsupported access strategy : " + accessType + ".");
// }
// }
// }
| import kr.pe.kwonnam.hibernate4memcached.regions.EntityMemcachedRegion;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.mockito.Mockito.verify; | package kr.pe.kwonnam.hibernate4memcached.strategies;
@RunWith(MockitoJUnitRunner.class)
public class NonstrictReadWriteEntityRegionAccessStrategyTest {
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Mock | // Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/regions/EntityMemcachedRegion.java
// public class EntityMemcachedRegion extends TransactionalDataMemcachedRegion implements EntityRegion {
// public EntityMemcachedRegion(String regionName, OverridableReadOnlyProperties properties, CacheDataDescription metadata, Settings settings, MemcachedAdapter memcachedAdapter, HibernateCacheTimestamper hibernateCacheTimestamper) {
// super(new CacheNamespace(regionName, true), properties, metadata, settings, memcachedAdapter, hibernateCacheTimestamper);
// }
//
// @Override
// public EntityRegionAccessStrategy buildAccessStrategy(AccessType accessType) throws CacheException {
// switch (accessType) {
// case READ_ONLY:
// return new ReadOnlyEntityRegionAccessStrategy(this);
// case NONSTRICT_READ_WRITE:
// return new NonstrictReadWriteEntityRegionAccessStrategy(this);
// default:
// throw new CacheException("Unsupported access strategy : " + accessType + ".");
// }
// }
// }
// Path: hibernate4-memcached-core/src/test/java/kr/pe/kwonnam/hibernate4memcached/strategies/NonstrictReadWriteEntityRegionAccessStrategyTest.java
import kr.pe.kwonnam.hibernate4memcached.regions.EntityMemcachedRegion;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.mockito.Mockito.verify;
package kr.pe.kwonnam.hibernate4memcached.strategies;
@RunWith(MockitoJUnitRunner.class)
public class NonstrictReadWriteEntityRegionAccessStrategyTest {
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Mock | private EntityMemcachedRegion entityMemcachedRegion; |
kwon37xi/hibernate4-memcached | hibernate4-memcached-core/src/test/java/kr/pe/kwonnam/hibernate4memcached/strategies/ReadOnlyEntityRegionAccessStrategyTest.java | // Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/regions/EntityMemcachedRegion.java
// public class EntityMemcachedRegion extends TransactionalDataMemcachedRegion implements EntityRegion {
// public EntityMemcachedRegion(String regionName, OverridableReadOnlyProperties properties, CacheDataDescription metadata, Settings settings, MemcachedAdapter memcachedAdapter, HibernateCacheTimestamper hibernateCacheTimestamper) {
// super(new CacheNamespace(regionName, true), properties, metadata, settings, memcachedAdapter, hibernateCacheTimestamper);
// }
//
// @Override
// public EntityRegionAccessStrategy buildAccessStrategy(AccessType accessType) throws CacheException {
// switch (accessType) {
// case READ_ONLY:
// return new ReadOnlyEntityRegionAccessStrategy(this);
// case NONSTRICT_READ_WRITE:
// return new NonstrictReadWriteEntityRegionAccessStrategy(this);
// default:
// throw new CacheException("Unsupported access strategy : " + accessType + ".");
// }
// }
// }
| import kr.pe.kwonnam.hibernate4memcached.regions.EntityMemcachedRegion;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import static org.fest.assertions.api.Assertions.*; | package kr.pe.kwonnam.hibernate4memcached.strategies;
@RunWith(MockitoJUnitRunner.class)
public class ReadOnlyEntityRegionAccessStrategyTest {
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Mock | // Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/regions/EntityMemcachedRegion.java
// public class EntityMemcachedRegion extends TransactionalDataMemcachedRegion implements EntityRegion {
// public EntityMemcachedRegion(String regionName, OverridableReadOnlyProperties properties, CacheDataDescription metadata, Settings settings, MemcachedAdapter memcachedAdapter, HibernateCacheTimestamper hibernateCacheTimestamper) {
// super(new CacheNamespace(regionName, true), properties, metadata, settings, memcachedAdapter, hibernateCacheTimestamper);
// }
//
// @Override
// public EntityRegionAccessStrategy buildAccessStrategy(AccessType accessType) throws CacheException {
// switch (accessType) {
// case READ_ONLY:
// return new ReadOnlyEntityRegionAccessStrategy(this);
// case NONSTRICT_READ_WRITE:
// return new NonstrictReadWriteEntityRegionAccessStrategy(this);
// default:
// throw new CacheException("Unsupported access strategy : " + accessType + ".");
// }
// }
// }
// Path: hibernate4-memcached-core/src/test/java/kr/pe/kwonnam/hibernate4memcached/strategies/ReadOnlyEntityRegionAccessStrategyTest.java
import kr.pe.kwonnam.hibernate4memcached.regions.EntityMemcachedRegion;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import static org.fest.assertions.api.Assertions.*;
package kr.pe.kwonnam.hibernate4memcached.strategies;
@RunWith(MockitoJUnitRunner.class)
public class ReadOnlyEntityRegionAccessStrategyTest {
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Mock | private EntityMemcachedRegion entityMemcachedRegion; |
kwon37xi/hibernate4-memcached | hibernate4-memcached-spymemcached-adapter/src/main/java/kr/pe/kwonnam/hibernate4memcached/spymemcached/KryoTranscoder.java | // Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/util/IntToBytesUtils.java
// public class IntToBytesUtils {
//
// /**
// * int value to 4 bytes array.
// */
// public static byte[] intToBytes(int value) {
// return new byte[]{(byte) (value >>> 24), (byte) (value >>> 16), (byte) (value >>> 8), (byte) (value)
//
// };
// }
//
// /**
// * 4 bytes array to int
// */
// public static int bytesToInt(byte[] bytes) {
// int value = ((int) bytes[0] & 0xFF) << 24;
// value += ((int) bytes[1] & 0xFF) << 16;
// value += ((int) bytes[2] & 0xFF) << 8;
// value += (int) bytes[3] & 0xFF;
// return value;
// }
//
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/util/Lz4CompressUtils.java
// public class Lz4CompressUtils {
// private static final LZ4Factory factory = LZ4Factory.fastestInstance();
//
// public static byte[] compress(final byte[] src) {
// if (src == null) {
// throw new IllegalArgumentException("src must not be null.");
// }
//
// LZ4Compressor compressor = factory.fastCompressor();
//
// return compressor.compress(src);
// }
//
// /**
// * When the exact decompressed size is unknown.
// * Decompress data size cannot be larger then maxDecompressedSize
// */
// public static byte[] decompressSafe(final byte[] src, int maxDecompressedSize) {
// if (src == null) {
// throw new IllegalArgumentException("src must not be null.");
// }
//
// if (maxDecompressedSize <= 0) {
// throw new IllegalArgumentException("maxDecompressedSize must be larger than 0 but " + maxDecompressedSize);
// }
//
// LZ4SafeDecompressor decompressor = factory.safeDecompressor();
//
// return decompressor.decompress(src, maxDecompressedSize);
// }
//
// /**
// * When the exact decompressed size is known, use this method to decompress. It's faster.
// *
// * @see net.jpountz.lz4.LZ4FastDecompressor
// */
// public static byte[] decompressFast(byte[] src, int srcOffset, int exactDecompressedSize) {
// if (src == null) {
// throw new IllegalArgumentException("src must not be null.");
// }
//
// if (srcOffset < 0) {
// throw new IllegalArgumentException("srcOffset must equal to or larger than 0 but " + srcOffset);
// }
//
// if (exactDecompressedSize < 0) {
// throw new IllegalArgumentException("exactDecompressedSize must equal to or larger than 0 but " + exactDecompressedSize);
// }
//
// LZ4FastDecompressor decompressor = factory.fastDecompressor();
//
// return decompressor.decompress(src, srcOffset, exactDecompressedSize);
// }
//
// /**
// * @see #decompressFast(byte[], int, int)
// */
// public static byte[] decompressFast(final byte[] src, int exactDecompressedSize) {
// return decompressFast(src, 0, exactDecompressedSize);
// }
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/util/OverridableReadOnlyProperties.java
// public interface OverridableReadOnlyProperties {
// String getProperty(String key);
//
// String getProperty(String key, String defaultValue);
//
// String getRequiredProperty(String key);
// }
| import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.io.Input;
import com.esotericsoftware.kryo.io.Output;
import com.esotericsoftware.kryo.serializers.CompatibleFieldSerializer;
import de.javakaffee.kryoserializers.KryoReflectionFactorySupport;
import kr.pe.kwonnam.hibernate4memcached.util.IntToBytesUtils;
import kr.pe.kwonnam.hibernate4memcached.util.Lz4CompressUtils;
import kr.pe.kwonnam.hibernate4memcached.util.OverridableReadOnlyProperties;
import net.spy.memcached.CachedData;
import org.apache.commons.lang3.ArrayUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.ByteArrayOutputStream;
import java.io.IOException; | package kr.pe.kwonnam.hibernate4memcached.spymemcached;
/**
* Default transcoder for {@link SpyMemcachedAdapter}.
*
* This transcoder uses Kryo Serializer and compress data with Lz4 when data size is greater than compression
* threashold.
*
* @author KwonNam Son ([email protected])
*/
public class KryoTranscoder implements InitializableTranscoder<Object> {
private Logger log = LoggerFactory.getLogger(KryoTranscoder.class);
public static final String COMPRESSION_THREASHOLD_PROPERTY_KEY = SpyMemcachedAdapter.PROPERTY_KEY_PREFIX + ".kryotranscoder.compression.threashold.bytes";
public static final int BASE_FLAG = 0;
public static final int COMPRESS_FLAG = 4; // 0b0100
public static final int DEFAULT_BUFFER_SIZE = 1024 * 20; // 20kb
public static final int DECOMPRESSED_SIZE_STORE_BYTES_LENGTH = 4;
| // Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/util/IntToBytesUtils.java
// public class IntToBytesUtils {
//
// /**
// * int value to 4 bytes array.
// */
// public static byte[] intToBytes(int value) {
// return new byte[]{(byte) (value >>> 24), (byte) (value >>> 16), (byte) (value >>> 8), (byte) (value)
//
// };
// }
//
// /**
// * 4 bytes array to int
// */
// public static int bytesToInt(byte[] bytes) {
// int value = ((int) bytes[0] & 0xFF) << 24;
// value += ((int) bytes[1] & 0xFF) << 16;
// value += ((int) bytes[2] & 0xFF) << 8;
// value += (int) bytes[3] & 0xFF;
// return value;
// }
//
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/util/Lz4CompressUtils.java
// public class Lz4CompressUtils {
// private static final LZ4Factory factory = LZ4Factory.fastestInstance();
//
// public static byte[] compress(final byte[] src) {
// if (src == null) {
// throw new IllegalArgumentException("src must not be null.");
// }
//
// LZ4Compressor compressor = factory.fastCompressor();
//
// return compressor.compress(src);
// }
//
// /**
// * When the exact decompressed size is unknown.
// * Decompress data size cannot be larger then maxDecompressedSize
// */
// public static byte[] decompressSafe(final byte[] src, int maxDecompressedSize) {
// if (src == null) {
// throw new IllegalArgumentException("src must not be null.");
// }
//
// if (maxDecompressedSize <= 0) {
// throw new IllegalArgumentException("maxDecompressedSize must be larger than 0 but " + maxDecompressedSize);
// }
//
// LZ4SafeDecompressor decompressor = factory.safeDecompressor();
//
// return decompressor.decompress(src, maxDecompressedSize);
// }
//
// /**
// * When the exact decompressed size is known, use this method to decompress. It's faster.
// *
// * @see net.jpountz.lz4.LZ4FastDecompressor
// */
// public static byte[] decompressFast(byte[] src, int srcOffset, int exactDecompressedSize) {
// if (src == null) {
// throw new IllegalArgumentException("src must not be null.");
// }
//
// if (srcOffset < 0) {
// throw new IllegalArgumentException("srcOffset must equal to or larger than 0 but " + srcOffset);
// }
//
// if (exactDecompressedSize < 0) {
// throw new IllegalArgumentException("exactDecompressedSize must equal to or larger than 0 but " + exactDecompressedSize);
// }
//
// LZ4FastDecompressor decompressor = factory.fastDecompressor();
//
// return decompressor.decompress(src, srcOffset, exactDecompressedSize);
// }
//
// /**
// * @see #decompressFast(byte[], int, int)
// */
// public static byte[] decompressFast(final byte[] src, int exactDecompressedSize) {
// return decompressFast(src, 0, exactDecompressedSize);
// }
// }
//
// Path: hibernate4-memcached-core/src/main/java/kr/pe/kwonnam/hibernate4memcached/util/OverridableReadOnlyProperties.java
// public interface OverridableReadOnlyProperties {
// String getProperty(String key);
//
// String getProperty(String key, String defaultValue);
//
// String getRequiredProperty(String key);
// }
// Path: hibernate4-memcached-spymemcached-adapter/src/main/java/kr/pe/kwonnam/hibernate4memcached/spymemcached/KryoTranscoder.java
import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.io.Input;
import com.esotericsoftware.kryo.io.Output;
import com.esotericsoftware.kryo.serializers.CompatibleFieldSerializer;
import de.javakaffee.kryoserializers.KryoReflectionFactorySupport;
import kr.pe.kwonnam.hibernate4memcached.util.IntToBytesUtils;
import kr.pe.kwonnam.hibernate4memcached.util.Lz4CompressUtils;
import kr.pe.kwonnam.hibernate4memcached.util.OverridableReadOnlyProperties;
import net.spy.memcached.CachedData;
import org.apache.commons.lang3.ArrayUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
package kr.pe.kwonnam.hibernate4memcached.spymemcached;
/**
* Default transcoder for {@link SpyMemcachedAdapter}.
*
* This transcoder uses Kryo Serializer and compress data with Lz4 when data size is greater than compression
* threashold.
*
* @author KwonNam Son ([email protected])
*/
public class KryoTranscoder implements InitializableTranscoder<Object> {
private Logger log = LoggerFactory.getLogger(KryoTranscoder.class);
public static final String COMPRESSION_THREASHOLD_PROPERTY_KEY = SpyMemcachedAdapter.PROPERTY_KEY_PREFIX + ".kryotranscoder.compression.threashold.bytes";
public static final int BASE_FLAG = 0;
public static final int COMPRESS_FLAG = 4; // 0b0100
public static final int DEFAULT_BUFFER_SIZE = 1024 * 20; // 20kb
public static final int DECOMPRESSED_SIZE_STORE_BYTES_LENGTH = 4;
| private OverridableReadOnlyProperties properties; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.