This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.net.MalformedURLException; | |
import java.net.URL; | |
import java.net.URLClassLoader; | |
import java.util.ArrayList; | |
import java.util.List; | |
public class Class1 { | |
public static void main(String[] args) throws MalformedURLException, ClassNotFoundException { | |
final List<Class<?>> classes = new ArrayList<>(); | |
while (true) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package sample.web; | |
import org.apache.logging.log4j.util.Strings; | |
import org.springframework.security.config.annotation.web.builders.HttpSecurity; | |
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; | |
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; | |
import org.springframework.security.config.http.SessionCreationPolicy; | |
import org.springframework.security.core.Authentication; | |
import org.springframework.security.core.AuthenticationException; | |
import org.springframework.security.core.context.SecurityContext; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ObjectMapper mapper = new ObjectMapper(); | |
mapper.enableDefaultTypingAsProperty(ObjectMapper.DefaultTyping.NON_FINAL, "@class"); | |
ObjectMapper.DefaultTypeResolverBuilder resolverBuilder = new ObjectMapper.DefaultTypeResolverBuilder(ObjectMapper.DefaultTyping.NON_FINAL); | |
resolverBuilder.init(JsonTypeInfo.Id.CLASS, null).inclusion(JsonTypeInfo.As.PROPERTY); | |
resolverBuilder.typeProperty("@class"); | |
mapper.setDefaultTyping(resolverBuilder); | |
SubtypeResolver subtypeResolver = mapper.getSubtypeResolver(); | |
subtypeResolver.registerSubtypes(new NamedType(A.class, "Uvw")); | |
subtypeResolver.registerSubtypes(new NamedType(B.class, "Xyz")); | |
mapper.setSubtypeResolver(subtypeResolver); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SomeClass { | |
Map<String, Map<String, String>> someMethod() { | |
return ...; | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void main(String[] args) { | |
AbstractPurchase purchases[] = {...}; | |
Arrays.sort(purchases); | |
print(purchases); | |
/* http://docs.oracle.com/javase/7/docs/api/java/util/Arrays.html#binarySearch(byte[],%20byte) | |
* binarySearch return index of the search key, if it is contained in the array; | |
* otherwise, (-(insertion point) - 1). Use it by create comparator without return 0 | |
* (equals) section. binarySearch with this comparator always return insertion point. | |
*/ | |
final long SEARCH_COST = 5300; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void main(String[] args) { | |
AbstractPurchase purchases[] = {...}; | |
Arrays.sort(purchases); | |
print(purchases); | |
/* http://docs.oracle.com/javase/7/docs/api/java/util/Arrays.html#binarySearch(byte[],%20byte) | |
* binarySearch return index of the search key, if it is contained in the array; | |
* otherwise, (-(insertion point) - 1). Use it by create comparator without return 0 | |
* (equals) section. binarySearch with this comparator always return insertion point. | |
*/ | |
final long SEARCH_COST = 90000; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void main(String[] args) { | |
Commodity commodity = new Commodity("Milk", 10000); | |
AbstractPurchase purchases[] = {...}; | |
Arrays.sort(purchases); | |
print(purchases); | |
/* Search */ | |
int finder = purchases.length; | |
int result = -1; | |
/* AbstractPurchase instance with cost returns search value. | |
* No needed to write own comparator because AbstractPurchase implements 'comparable'. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int[] arr = {1,2,7,4,5,7,5,7,6,7,0,-1,22,15}; | |
Arrays.sort(arr); | |
for (int i = 0; i < arr.length; i++) { | |
System.out.println(i + " : " + arr[i]); | |
} | |
System.out.println("RES:"); | |
int match = Arrays.binarySearch(arr, 7); | |
if (match >= 0) { | |
int first = match; | |
int last = match; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <algorithm> | |
#include <string> | |
#include <vector> | |
#include <windows.h> | |
#pragma GCC diagnostic ignored "-Wwrite-strings" | |
using namespace std; | |
class Purchase { |
NewerOlder