method2testcases stringlengths 118 6.63k |
|---|
### Question:
Primitives { public static boolean isPrimitive(Field field) { return isPrimitive(field.getType()); } private Primitives(); static void registerPrimitiveClass(Class primitiveClass); @SneakyThrows static void registerPrimitiveClass(Class primitiveClass, Object primitiveDefault); @SuppressWarnings("unchecke... |
### Question:
Primitives { public static boolean isTimeType(Class clazz) { return clazz.equals(Date.class) || clazz.equals(Instant.class) || clazz.equals(Long.class); } private Primitives(); static void registerPrimitiveClass(Class primitiveClass); @SneakyThrows static void registerPrimitiveClass(Class primitiveClass,... |
### Question:
Primitives { @SuppressWarnings("unchecked") public static <T> T toTimeType(Object timeValue, Class<T> targetTimeType) { Class valueClass = timeValue.getClass(); Function<Object, Object> timeConverter = TIME_CONVERTERS.get(new Pair(valueClass, targetTimeType)); if (timeConverter == null) { throw Element.Ex... |
### Question:
HasKeys implements ElementTo.Element { @SuppressWarnings("PMD.ShortMethodName") public static HasKeys of(org.apache.tinkerpop.gremlin.object.structure.Element element, Class<? extends Annotation> keyType) { return HasKeys.builder() .element(element) .keyType(keyType) .build(); } @SuppressWarnings("PMD.Sh... |
### Question:
Parser { public static boolean isPropertyValue(Field field) { return has(field, PropertyValue.class); } private Parser(); static void registerElementParser(ElementParser<?> elementParser); static boolean isPropertyValue(Field field); @SneakyThrows @SuppressWarnings({"PMD.ShortMethodName", "rawtypes"}) st... |
### Question:
Parser { @SneakyThrows @SuppressWarnings({"PMD.ShortMethodName", "rawtypes"}) public static <T> T as(Object element, Class<T> objectClass) { Class<?> elementType = element.getClass(); if (is(elementType, objectClass)) { return (T) element; } for (ElementParser elementParser : ELEMENT_PARSERS) { if (is(ele... |
### Question:
Fields { public static boolean has(Field field, Class<? extends Annotation> annotationType) { return field.getAnnotation(annotationType) != null; } private Fields(); static boolean has(Field field, Class<? extends Annotation> annotationType); static String alias(AnnotatedElement element, Function<Alias, ... |
### Question:
Fields { public static String alias(AnnotatedElement element, Function<Alias, String> property) { Alias alias = element.getAnnotation(Alias.class); if (alias == null) { return null; } String value = property.apply(alias); return isNotEmpty(value) ? value : null; } private Fields(); static boolean has(Fie... |
### Question:
Fields { public static String propertyKey(Field field) { String key = alias(field, Alias::key); return key != null ? key : field.getName(); } private Fields(); static boolean has(Field field, Class<? extends Annotation> annotationType); static String alias(AnnotatedElement element, Function<Alias, String... |
### Question:
Fields { @SneakyThrows public static Object propertyValue(Field field, Object instance) { Object value = field.get(instance); if (isPrimitiveDefault(field, value)) { DefaultValue defaultValue = field.getAnnotation(DefaultValue.class); if (defaultValue != null) { return asPrimitiveType(field, defaultValue.... |
### Question:
Fields { public static <E extends Element> Field field(E element, String fieldName) { return field(element.getClass(), fieldName); } private Fields(); static boolean has(Field field, Class<? extends Annotation> annotationType); static String alias(AnnotatedElement element, Function<Alias, String> propert... |
### Question:
Fields { private Fields() {} private Fields(); static boolean has(Field field, Class<? extends Annotation> annotationType); static String alias(AnnotatedElement element, Function<Alias, String> property); static String propertyKey(Field field); @SneakyThrows static Object propertyValue(Field field, Objec... |
### Question:
Properties { @SuppressWarnings({"PMD.ShortMethodName"}) public static <E extends Element> Object[] id(E element) { return of(element, Keys::isKey); } private Properties(); @SuppressWarnings({"PMD.ShortMethodName"}) static Object[] id(E element); @SuppressWarnings({"PMD.ShortMethodName"}) static Object[] ... |
### Question:
Properties { @SuppressWarnings({"PMD.ShortMethodName"}) public static <E extends Element> Object[] all(E element) { return of(element, field -> true); } private Properties(); @SuppressWarnings({"PMD.ShortMethodName"}) static Object[] id(E element); @SuppressWarnings({"PMD.ShortMethodName"}) static Object... |
### Question:
HasLabel implements ElementTo.Element { @SuppressWarnings("PMD.ShortMethodName") public static HasLabel of(org.apache.tinkerpop.gremlin.object.structure.Element element) { return of(element.getClass()); } @SuppressWarnings("PMD.ShortMethodName") static HasLabel of(org.apache.tinkerpop.gremlin.object.stru... |
### Question:
Properties { @SuppressWarnings({"PMD.ShortMethodName"}) public static <V extends Vertex> Object[] of(V vertex) { return of(vertex, field -> !isKey(field)); } private Properties(); @SuppressWarnings({"PMD.ShortMethodName"}) static Object[] id(E element); @SuppressWarnings({"PMD.ShortMethodName"}) static O... |
### Question:
Properties { public static <E extends Element> List<String> names(E element) { return names(element, field -> true); } private Properties(); @SuppressWarnings({"PMD.ShortMethodName"}) static Object[] id(E element); @SuppressWarnings({"PMD.ShortMethodName"}) static Object[] all(E element); @SuppressWarnin... |
### Question:
Properties { @SneakyThrows @SuppressWarnings("unchecked") public static List<Object> values(Object object) { List<Object> properties = new ArrayList<>(); Class<?> objectClass = object.getClass(); if (isPrimitive(objectClass)) { properties.add(object); } else if (isElement(objectClass)) { for (Field field ... |
### Question:
Keys { public static boolean isPrimaryKey(Field field) { return has(field, PrimaryKey.class); } private Keys(); static boolean isKey(Field field); static boolean isPrimaryKey(Field field); static boolean isOrderingKey(Field field); static List<Field> keyFields(Element element); static List<Field> keyFiel... |
### Question:
Keys { public static boolean isOrderingKey(Field field) { return has(field, OrderingKey.class); } private Keys(); static boolean isKey(Field field); static boolean isPrimaryKey(Field field); static boolean isOrderingKey(Field field); static List<Field> keyFields(Element element); static List<Field> keyFi... |
### Question:
Keys { public static List<Field> primaryKeyFields(Element element) { return primaryKeyFields(element.getClass()); } private Keys(); static boolean isKey(Field field); static boolean isPrimaryKey(Field field); static boolean isOrderingKey(Field field); static List<Field> keyFields(Element element); static... |
### Question:
Keys { public static boolean hasPrimaryKeys(Element element) { return hasPrimaryKeys(element.getClass()); } private Keys(); static boolean isKey(Field field); static boolean isPrimaryKey(Field field); static boolean isOrderingKey(Field field); static List<Field> keyFields(Element element); static List<Fi... |
### Question:
Keys { public static List<Field> orderingKeyFields(Element element) { return orderingKeyFields(element.getClass()); } private Keys(); static boolean isKey(Field field); static boolean isPrimaryKey(Field field); static boolean isOrderingKey(Field field); static List<Field> keyFields(Element element); stat... |
### Question:
Keys { public static List<String> primaryKeyNames(Element element) { return primaryKeyNames(element); } private Keys(); static boolean isKey(Field field); static boolean isPrimaryKey(Field field); static boolean isOrderingKey(Field field); static List<Field> keyFields(Element element); static List<Field>... |
### Question:
Keys { @SneakyThrows @SuppressWarnings("PMD.ShortMethodName") public static <E extends Element> Object id(E element) { if (element == null) { return null; } Object elementId = element.id(); if (elementId != null) { return elementId; } Map<String, Object> mappedId = new HashMap<>(); if (isVertex(element)) ... |
### Question:
Values implements ElementTo.Any { @SuppressWarnings("PMD.ShortMethodName") public static Values of(org.apache.tinkerpop.gremlin.object.structure.Element element) { return of(Properties.names(element)); } @SuppressWarnings("PMD.ShortMethodName") static Values of(org.apache.tinkerpop.gremlin.object.structu... |
### Question:
Vertex extends Element { public void remove() { org.apache.tinkerpop.gremlin.structure.Vertex delegate = delegate(); if (delegate == null) { throw Element.Exceptions.removingDetachedElement(this); } delegate.remove(); } Vertex(Element element); org.apache.tinkerpop.gremlin.structure.Vertex delegate(); voi... |
### Question:
VertexGraph extends ElementGraph { protected <V extends Vertex> GraphTraversal update(V vertex) { GraphTraversal traversal = find(vertex); return update(traversal, vertex, Properties::of); } VertexGraph(Graph graph, GraphTraversalSource g); org.apache.tinkerpop.gremlin.structure.Vertex delegate(V vertex);... |
### Question:
VertexGraph extends ElementGraph { public <V extends Vertex> Vertex addVertex(V vertex) { vertex.validate(); org.apache.tinkerpop.gremlin.structure.Vertex delegate; switch (should()) { case CREATE: delegate = complete(create(vertex)); break; case MERGE: delegate = complete(g.inject(1).coalesce( update(ver... |
### Question:
VertexGraph extends ElementGraph { public <V extends Vertex> Vertex removeVertex(V vertex) { GraphTraversal traversal = find(vertex); log.info("Executing 'remove vertex' traversal {} ", traversal); traversal.drop().toList(); if (vertex.id() != null) { delegates.remove(vertex); } observers.notifyAll(observ... |
### Question:
EdgeGraph extends ElementGraph { <E extends Edge> GraphTraversal find(E edge, Object fromId, Object toId) { return g.V() .hasId(fromId).as("from") .outE(edge.label()).as("edge") .inV().hasId(toId).as("to") .select("edge"); } EdgeGraph(Graph graph, Query query, GraphTraversalSource g); org.apache.tinkerpop... |
### Question:
Keys implements ElementTo.Any { @SuppressWarnings("PMD.ShortMethodName") public static Keys of(org.apache.tinkerpop.gremlin.object.structure.Element element) { return of(element.getClass()); } @SuppressWarnings("PMD.ShortMethodName") static Keys of(org.apache.tinkerpop.gremlin.object.structure.Element el... |
### Question:
EdgeGraph extends ElementGraph { <E extends Edge> GraphTraversal update(E edge, Object fromId, Object toId) { GraphTraversal traversal = find(edge, fromId, toId); return update(traversal, edge, Properties::of); } EdgeGraph(Graph graph, Query query, GraphTraversalSource g); org.apache.tinkerpop.gremlin.str... |
### Question:
EdgeGraph extends ElementGraph { public <E extends Edge> Edge removeEdge(E edge) { if (edge.fromId() == null || edge.toId() == null) { throw Element.Exceptions.removingDetachedElement(edge); } GraphTraversal traversal = find(edge, edge.fromId(), edge.toId()); log.info("Executing 'remove edge' traversal {}... |
### Question:
ElementGraph { protected <E extends Element> GraphTraversal find(E element) { GraphTraversal traversal = g.V(); if (element.id() != null) { traversal = traversal.hasId(element.id()); } else { traversal = traversal.hasLabel(element.label()); Object[] properties = Properties.id(element); if (properties == n... |
### Question:
ElementGraph { protected <E extends Element> GraphTraversal update( GraphTraversal traversal, E element, Function<E, Object[]> lister) { return update(traversal, UpdateBy.TRAVERSAL, element, lister); } }### Answer:
@Test public void testUpdateElement() { Location location = (Location) createElement(); ... |
### Question:
Element implements Comparable<Element> { @SuppressWarnings({"PMD.ShortMethodName"}) public final Object id() { if (userSuppliedId != null) { return userSuppliedId; } if (delegate != null) { return delegate.id(); } return null; } Element(Element other); final String label(); @SuppressWarnings({"PMD.ShortMe... |
### Question:
Element implements Comparable<Element> { public final String label() { return Label.of(getClass()); } Element(Element other); final String label(); @SuppressWarnings({"PMD.ShortMethodName"}) final Object id(); @SneakyThrows @SuppressWarnings({"PMD.ShortMethodName"}) ElementTo.Element s(String key); void v... |
### Question:
Element implements Comparable<Element> { public boolean existsIn(Collection<? extends Element> elements) { final List<Field> fields = keyFields(getClass()); if (fields.isEmpty()) { fields.addAll(fields(getClass())); } return elements.stream() .anyMatch(element -> valuesOf(fields).compare(element, this) ==... |
### Question:
Edge extends Element { @SuppressWarnings("PMD.CloseResource") public boolean connects(Vertex from, Vertex to) { return connects(from.getClass(), to.getClass()); } org.apache.tinkerpop.gremlin.structure.Edge delegate(); V fromAs(Class<V> vertexType); V toAs(Class<V> vertexType); @SuppressWarnings("PMD.Clo... |
### Question:
Classes { public static boolean isElement(Class<?> type) { return is(type, Element.class); } private Classes(); static boolean isElement(Class<?> type); static boolean isVertex(Object object); static boolean isVertex(Class<?> type); static boolean isEdge(Object object); static boolean isEdge(Class<?> typ... |
### Question:
Classes { public static boolean isVertex(Object object) { return object != null && isVertex(object.getClass()); } private Classes(); static boolean isElement(Class<?> type); static boolean isVertex(Object object); static boolean isVertex(Class<?> type); static boolean isEdge(Object object); static boolea... |
### Question:
Classes { public static boolean isEdge(Object object) { return object != null && isEdge(object.getClass()); } private Classes(); static boolean isElement(Class<?> type); static boolean isVertex(Object object); static boolean isVertex(Class<?> type); static boolean isEdge(Object object); static boolean is... |
### Question:
Classes { public static boolean isList(Object object) { return object != null && isList(object.getClass()); } private Classes(); static boolean isElement(Class<?> type); static boolean isVertex(Object object); static boolean isVertex(Class<?> type); static boolean isEdge(Object object); static boolean is... |
### Question:
CounterViewModel extends BaseObservable { @Bindable public int getCount() { return count; } void increment(); void decrement(); @Bindable int getCount(); }### Answer:
@Test public void testInitialState() { Assert.assertEquals(0, counterViewModel.getCount()); } |
### Question:
CounterViewModel extends BaseObservable { public void increment() { setCount(getCount() + 1); } void increment(); void decrement(); @Bindable int getCount(); }### Answer:
@Test public void testIncrement() { for (int i = 1; i <= 5; i++) { counterViewModel.increment(); Assert.assertEquals(i, counterViewMo... |
### Question:
CounterViewModel extends BaseObservable { public void decrement() { setCount(getCount() - 1); } void increment(); void decrement(); @Bindable int getCount(); }### Answer:
@Test public void testDecrement() { for (int i = 1; i <= 5; i++) { counterViewModel.decrement(); Assert.assertEquals(i * -1, counterV... |
### Question:
IniRealmDemo { public boolean helloShiro(String username, String password) { initSecurityUtils(); UsernamePasswordToken usernamePasswordToken = new UsernamePasswordToken(username, password); usernamePasswordToken.setRememberMe(true); Subject currentUser = SecurityUtils.getSubject(); try { currentUser.logi... |
### Question:
StaticCglibProxyDemo extends UserServiceImpl { @Override public void removeUser(String name) { log.warn("before remove user"); super.removeUser(name); log.warn("after remove user"); } @Override void addUser(String name); @Override void removeUser(String name); @Override String getUsername(String name); ... |
### Question:
StaticCglibProxyDemo extends UserServiceImpl { @Override public String getUsername(String name) { log.warn("before get username"); String username = super.getUsername(name); log.warn("after get username"); return username; } @Override void addUser(String name); @Override void removeUser(String name); @Ov... |
### Question:
JDKProxyDemo { public UserService getUserService(){ ProxyHandler proxyHandler = new ProxyHandler(userService); return (UserService) Proxy.newProxyInstance(proxyHandler.getClass().getClassLoader(),userService.getClass().getInterfaces(),proxyHandler); } UserService getUserService(); }### Answer:
@Test voi... |
### Question:
CglibProxyDemo { public UserService getUserService(){ Enhancer en = new Enhancer(); en.setSuperclass(userService.getClass()); en.setCallback((MethodInterceptor) (arg0, method, args, arg3) -> { log.info("pre class: {} method: {} return type:{} args:{}", userService.getClass().getName(),method.getName(),met... |
### Question:
LogAop { @Pointcut("execution(public * org.laidu.learn.spring.aop.service..*(..))") public void serviceLog(){} @Pointcut("execution(* org.laidu.learn.spring.aop.service..*(..))") void serviceLog(); @Before("serviceLog()") void doBefore(JoinPoint joinPoint); @AfterReturning(returning = "ret", pointcut = "... |
### Question:
UserServiceImpl implements UserService { @Override @Cacheable("getUserInfo") public UserInfo getUserInfo(String key) { UserInfo userInfo = redisTemplate.opsForValue().get(key); if (userInfo == null) { log.info("cache null : {}", key); userInfo = addUser("demo","demo"); } return userInfo; } @Autowired Use... |
### Question:
UserServiceImpl implements UserService { @Override @Cacheable("userinfo") public UserInfo addUser(String username, String password) { return UserInfo.builder() .userId(UUID.randomUUID().toString()) .username(username) .build(); } @Autowired UserServiceImpl(RedisTemplate<String, UserInfo> redisTemplate); ... |
### Question:
UserServiceImpl implements UserService { @Override public UserInfo updateUsername(String id, String username) { boolean res = false; UserInfo info = null; RLock lock = redission.getLock("lock_"+id); try { lock.lock(10, TimeUnit.SECONDS); System.out.println("got lock"); }catch (Exception e){ log.warn("获取re... |
### Question:
SpringClientDemo implements ClientDemo { @Override public void declareQueue() throws IOException { RabbitAdmin rabbitAdmin = rabbitAdmin(); try { rabbitAdmin.declareQueue(new Queue("demo2",false,false,false)); }catch (Exception e){ try { if (406 == ((AMQImpl.Channel.Close) ((ShutdownSignalException)e.getC... |
### Question:
ExtendClass implements InterfaceA,InterfaceB { @Override public void sayHello() { log.debug("-*--*--*--*--*--*--*--*--*-- sayHello --*--*--*--*--*--*--*--*--*-: {}","123"); } @Override void sayHello(); @Override void sayBye(); @Override void sayGood(); static void main(String[] args); }### Answer:
@Test... |
### Question:
ExtendClass implements InterfaceA,InterfaceB { @Override public void sayBye() { ((InterfaceA) () -> log.debug("-*--*--*--*--*--*--*--*--*-- sayGood --*--*--*--*--*--*--*--*--*-: {}","good")).sayBye(); } @Override void sayHello(); @Override void sayBye(); @Override void sayGood(); static void main(String[... |
### Question:
ExtendClass implements InterfaceA,InterfaceB { @Override public void sayGood() { log.debug("-*--*--*--*--*--*--*--*--*-- sayGood --*--*--*--*--*--*--*--*--*-: {}","good"); } @Override void sayHello(); @Override void sayBye(); @Override void sayGood(); static void main(String[] args); }### Answer:
@Test ... |
### Question:
ListStreamDemo { public static String list2String(List<String> list){ return list.parallelStream().collect(Collectors.joining(",")); } static String list2String(List<String> list); static String list2String2(List<String> list); static List<Student> distinctBy(List<Student> students); }### Answer:
@Test ... |
### Question:
ListStreamDemo { public static String list2String2(List<String> list){ return String.join(",",list); } static String list2String(List<String> list); static String list2String2(List<String> list); static List<Student> distinctBy(List<Student> students); }### Answer:
@Test void list2String2() { log.info("... |
### Question:
StringPartMethod { public static String join(CharSequence delimiter, CharSequence... elements) { Objects.requireNonNull(delimiter); Objects.requireNonNull(elements); StringJoiner joiner = new StringJoiner(delimiter); for (CharSequence cs: elements) { joiner.add(cs); } return joiner.toString(); } static S... |
### Question:
CurlParserUtil { public Map<String, String> getHeaders(String curlLine) { Map<String, String> keyValuePairs = keyValuePairs(curlLine); keyValuePairs.remove("Content-Length"); return keyValuePairs; } private CurlParserUtil(); static CurlParserUtil getInstance(); Map<String, String> getHeaders(String curlL... |
### Question:
CurlParserUtil { public Map<String, String> getCookies(String curlLine) { Map<String, String> cookieMap = new HashMap<>(); StringBuilder cookiesString = new StringBuilder(); cookiesString.append(getHeaders(curlLine).get("Cookie")); cookiesString.append(getBCookiesString(curlLine)); if (StringUtil.isNotBla... |
### Question:
CurlParserUtil { public String getMethod(String curlLine) { String methodPattern = "-X \\$'([A-Z]{2,5})'"; int methodIndex = 1; return RegexUtil.getInstance().getMacthResult(methodPattern, curlLine, methodIndex, "GET"); } private CurlParserUtil(); static CurlParserUtil getInstance(); Map<String, String> ... |
### Question:
RabbitmqClientDemo implements ClientDemo { public ConnectionFactory connectionFactory(){ ConnectionFactory connectionFactory = new ConnectionFactory(); connectionFactory.setHost("dev"); connectionFactory.setPort(5672); connectionFactory.setUsername("admin"); connectionFactory.setPassword("admin"); connect... |
### Question:
CurlParserUtil { public String getUrl(String curlLine) { String urlPattern = "\\$'(https?: int urlIndex = 1; return RegexUtil.getInstance().getMacthResult(urlPattern, curlLine, urlIndex); } private CurlParserUtil(); static CurlParserUtil getInstance(); Map<String, String> getHeaders(String curlLine); Map... |
### Question:
CurlParserUtil { public String getBodyString(String curlLine) { String stringBodyPattern = "--data-binary \\$'([^\\$]*)'"; int stringBodyIndex = 1; return RegexUtil.getInstance().getMacthResult(stringBodyPattern, curlLine, stringBodyIndex); } private CurlParserUtil(); static CurlParserUtil getInstance();... |
### Question:
CurlParserUtil { public Map<String, String> getFormBody(String curlLine) { Map<String, String> formMap = new HashMap<>(); String formBodyString = getBodyString(curlLine); String formDataPattern = "([^=&]+=[^&']*)+"; int formDataIndex = 1; List<String> formStringList = RegexUtil.getInstance().getMacthAllRe... |
### Question:
JAXBUtil { public String obj2Xml(Object obj) throws JAXBException, UnsupportedEncodingException { ByteArrayOutputStream os = new ByteArrayOutputStream(); JAXBContext jaxbContext = JAXBContext.newInstance(obj.getClass()); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); jaxbMarshaller.setPropert... |
### Question:
JAXBUtil { public <T> T xml2Obj(String xmlSource, Class<T> clazz) throws JAXBException { JAXBContext context; context = JAXBContext.newInstance(clazz); Unmarshaller unmarshal = context.createUnmarshaller(); T obj = (T) unmarshal.unmarshal(new StringReader(xmlSource)); return obj; } private JAXBUtil(); st... |
### Question:
RegexUtil { public List<String> getMacthAllResult(String regex, String source, int index) { return getMacthAllResult(Pattern.compile(regex),source,index); } private RegexUtil(); static RegexUtil getInstance(); List<String> getMacthAllResult(String regex, String source, int index); List<String> getMacthAl... |
### Question:
RegexUtil { public String getMacthResult(String regex, String source, int index) { return getMacthResult(regex,source,index,null); } private RegexUtil(); static RegexUtil getInstance(); List<String> getMacthAllResult(String regex, String source, int index); List<String> getMacthAllResult(Pattern pattern,... |
### Question:
AESEncryptionUtil { public byte[] cbcEncrypt(byte[] data, byte[] key, byte[] ivp) { return BasicEncryptionUtil.getInstance().encrypt(HelperHolder.ALGORITHM, HelperHolder.ALGORITHM_CBC_KEY, key, ivp, data); } private AESEncryptionUtil(); static AESEncryptionUtil getInstance(); byte[] cbcEncrypt(byte[] dat... |
### Question:
AESEncryptionUtil { public byte[] cbcDecrypt(byte[] data, byte[] key, byte[] ivp) { return BasicEncryptionUtil.getInstance().decrypt(HelperHolder.ALGORITHM, HelperHolder.ALGORITHM_CBC_KEY, key, ivp, data); } private AESEncryptionUtil(); static AESEncryptionUtil getInstance(); byte[] cbcEncrypt(byte[] dat... |
### Question:
AESEncryptionUtil { public byte[] ecbDecrypt(byte[] data, byte[] key){ return BasicEncryptionUtil.getInstance().decrypt(HelperHolder.ALGORITHM, HelperHolder.ALGORITHM_ECB_KEY, key, null, data); } private AESEncryptionUtil(); static AESEncryptionUtil getInstance(); byte[] cbcEncrypt(byte[] data, byte[] ke... |
### Question:
RabbitmqClientDemo implements ClientDemo { public Connection connection(ConnectionFactory connectionFactory){ Connection connection = null; try { connection = connectionFactory.newConnection(); } catch (Exception e) { log.error("connection create error", e); } return connection; } ConnectionFactory conne... |
### Question:
MD5Util { public String toMd5(String origin){ String re_md5 = ""; try { MessageDigest md = MessageDigest.getInstance("MD5"); md.update(origin.getBytes()); byte b[] = md.digest(); md = null; int i; StringBuffer buf = new StringBuffer(""); for (int offset = 0; offset < b.length; offset++) { i = b[offset]; i... |
### Question:
RSAencryptionUtil { public RSAPrivateKey getPrivateKey(Map<String, Object> keyMap){ RSAPrivateKey privateKey = (RSAPrivateKey) keyMap.get(HelperHolder.PRIVATE_KEY); return privateKey; } private RSAencryptionUtil(); static RSAencryptionUtil getInstance(); Map<String, Object> initKey(); RSAPublicKey getpub... |
### Question:
RSAencryptionUtil { public byte[] decrypt(byte[] data, RSAPrivateKey privateKey) throws Exception{ return BasicEncryptionUtil.getInstance().decrypt(HelperHolder.ALGOROTHM_KEY,privateKey,data); } private RSAencryptionUtil(); static RSAencryptionUtil getInstance(); Map<String, Object> initKey(); RSAPublicK... |
### Question:
SearchInDoubleDimArray { public static boolean findByBinarySearch(int target, int [][] array) { if (array.length <= 0){ return false; } if (array[0].length <= 0){ return false; } int rowSize = array.length; int rankSize = array[0].length; if (target < array[0][0] || target > array[rowSize-1][rankSize-1]){... |
### Question:
DoubleStackArithmeticExpression { public int calculate(String expression){ Stack<Integer> vals = new Stack<>(); Stack<Character> op = new Stack<>(); for (char var : expression.toCharArray()){ } return 0; } int calculate(String expression); }### Answer:
@Test void calculate() { String expression = "(2+(2... |
### Question:
FirstMissingPositive { public int firstMissingPositive(int[] nums) { int n = nums.length; if (n == 0) { return 1; } if (n == 1) { return nums[0] == 1 ? 2 : 1; } for (int i = 0; i < n; i++) { while (nums[i] > 0 && nums[i] < n && nums[i] != nums[nums[i]]) { swap(nums, i, nums[i]); } } for (int i = 1; i < n;... |
### Question:
FirstMissingPositive { public int firstMissingPositive2(int[] nums) { if (nums.length == 0) { return 1; } if (nums.length == 1) { return nums[0] == 1 ? 2 : 1; } int min = 1; while (contain(nums, min) || min < 1) { ++min; } return min; } int firstMissingPositive(int[] nums); int firstMissingPositive2(int[... |
### Question:
RabbitmqClientDemo implements ClientDemo { @Override public void declareQueue() throws IOException { Connection connection = connection(connectionFactory()); Channel channel = connection.createChannel(); try { channel.queueDeclare("demo1",true,false,false,null); }catch (IOException e){ if ("406".equals(((... |
### Question:
TwoSum { public int[] twoSum(int[] nums, int target) { int len = nums.length; HashMap<Integer, Integer> map = new HashMap<>(); for (int i = 0; i < len; ++i) { if (map.containsKey(nums[i])) { return new int[]{map.get(nums[i]), i}; } map.put(target - nums[i], i); } return null; } int[] twoSum(int[] nums, i... |
### Question:
MethodMonitorProcessor { @Around("pointcut() && @annotation(monitor)") public Object logExecutionTime(ProceedingJoinPoint joinPoint, MethodMonitor monitor) throws Throwable { MethodMonitor.LogPrintLogic logPrintLogic; try { logPrintLogic = context.getBean(monitor.logic()); }catch (Exception ex){ log.error... |
### Question:
StaticJdkProxyDemo implements UserService { @Override public void addUser(String name) { log.warn("before add user"); userService.addUser(name); log.warn("after add user"); } @Override void addUser(String name); @Override void removeUser(String name); @Override String getUsername(String name); @Override ... |
### Question:
StaticJdkProxyDemo implements UserService { @Override public void removeUser(String name) { log.warn("before remove user"); userService.removeUser(name); log.warn("after remove user"); } @Override void addUser(String name); @Override void removeUser(String name); @Override String getUsername(String name)... |
### Question:
StaticJdkProxyDemo implements UserService { @Override public String getUsername(String name) { log.warn("before get username"); String username = userService.getUsername(name); log.warn("after get username"); return username; } @Override void addUser(String name); @Override void removeUser(String name); ... |
### Question:
StaticCglibProxyDemo extends UserServiceImpl { @Override public void addUser(String name) { log.warn("before add user"); super.addUser(name); log.warn("after add user"); } @Override void addUser(String name); @Override void removeUser(String name); @Override String getUsername(String name); }### Answer:... |
### Question:
ClientWave { public Wavelet fetchWavelet(WaveId waveId, WaveletId waveletId) throws ClientWaveException { return fetchWavelet(waveId, waveletId, null); } ClientWave(JSONRpcHandler jsonHandler); List<JsonRpcResponse> submit(Wavelet wavelet); Wavelet blindWavelet(WaveId waveId, WaveletId waveletId); Wavelet... |
### Question:
DatastoreFactory { public HttpRequestFactory makeClient(DatastoreOptions options) { Credential credential = options.getCredential(); HttpTransport transport = options.getTransport(); if (transport == null) { transport = credential == null ? new NetHttpTransport() : credential.getTransport(); transport = t... |
### Question:
Datastore { public AllocateIdsResponse allocateIds(AllocateIdsRequest request) throws DatastoreException { try (InputStream is = remoteRpc.call("allocateIds", request)) { return AllocateIdsResponse.parseFrom(is); } catch (IOException exception) { throw invalidResponseException("allocateIds", exception); }... |
### Question:
Datastore { public LookupResponse lookup(LookupRequest request) throws DatastoreException { try (InputStream is = remoteRpc.call("lookup", request)) { return LookupResponse.parseFrom(is); } catch (IOException exception) { throw invalidResponseException("lookup", exception); } } Datastore(RemoteRpc remoteR... |
### Question:
Datastore { public BeginTransactionResponse beginTransaction(BeginTransactionRequest request) throws DatastoreException { try (InputStream is = remoteRpc.call("beginTransaction", request)) { return BeginTransactionResponse.parseFrom(is); } catch (IOException exception) { throw invalidResponseException("be... |
### Question:
Datastore { public CommitResponse commit(CommitRequest request) throws DatastoreException { try (InputStream is = remoteRpc.call("commit", request)) { return CommitResponse.parseFrom(is); } catch (IOException exception) { throw invalidResponseException("commit", exception); } } Datastore(RemoteRpc remoteR... |
### Question:
Datastore { public ReserveIdsResponse reserveIds(ReserveIdsRequest request) throws DatastoreException { try (InputStream is = remoteRpc.call("reserveIds", request)) { return ReserveIdsResponse.parseFrom(is); } catch (IOException exception) { throw invalidResponseException("reserveIds", exception); } } Dat... |
### Question:
Datastore { public RollbackResponse rollback(RollbackRequest request) throws DatastoreException { try (InputStream is = remoteRpc.call("rollback", request)) { return RollbackResponse.parseFrom(is); } catch (IOException exception) { throw invalidResponseException("rollback", exception); } } Datastore(Remot... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.