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.io.*; | |
public class CVJNI { | |
//Load jni library | |
static { | |
try { | |
System.loadLibrary("cvjni"); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} |
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.util.*; | |
public class Iter { | |
public static void main(String[] args) { | |
Aggregate<Integer, Integer, Integer> ag = new DataList<Integer, Integer, Integer>(); | |
((DataList)ag).add(new ThreeD<Integer, Integer, Integer>(1, 2, 3)); | |
((DataList)ag).add(new ThreeD<Integer, Integer, Integer>(1, 2, 3)); | |
((DataList)ag).add(new ThreeD<Integer, Integer, Integer>(1, 2, 3)); | |
Iterator<Integer> ia = ag.createIteratorA(); | |
while (ia.next() != null) { |
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
keys = ['a', 'b'] | |
values = ['c', 'd'] | |
dictionary = dict(zip(keys, values)) |
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.util.LinkedList; | |
import java.util.List; | |
import java.util.Queue; | |
/* | |
* A solution using Proxy Pattern to limited instances problem | |
* Requirement: | |
* class RareResource must have no more than 3 instances at any run time. | |
* Note: | |
* Black magic like reflection is out of consideration as you can never prevent it. |
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.util.*; | |
public class Limiton { | |
private static int limit = 3; | |
private static Limiton[] instances = new Limiton[3]; | |
private static Random r = new Random(); | |
static { | |
for (int i = 0; i < limit; i++) { | |
instances[i] = new Limiton(); | |
} | |
} |
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
// Problem | |
abstract class VisualComponent { | |
void draw(); | |
void resize(); | |
} | |
class TextView extends VisualComponent { | |
void draw() {...} | |
void resize() {...} | |
} |
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.util.*; | |
public class Proxy { | |
public static void main(String[] args) { | |
} | |
} | |
class ThreeD<T, V, W> { | |
private T t; |
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.util.*; | |
public class Iter { | |
public static void main(String[] args) { | |
Aggregate<Integer, Integer, Integer> ag = new DataList<Integer, Integer, Integer>(); | |
((DataList)ag).add(new ThreeD<Integer, Integer, Integer>(1, 2, 3)); | |
((DataList)ag).add(new ThreeD<Integer, Integer, Integer>(1, 2, 3)); | |
((DataList)ag).add(new ThreeD<Integer, Integer, Integer>(1, 2, 3)); | |
Iterator<Integer> ia = ag.createIteratorA(); | |
while (ia.next() != null) { |
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
jbyteArray result = env->NewByteArray(imageDesV.size()); |
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
g++ -m64 -shared -fPIC cvjni.cpp /usr/local/lib/libopencv_core.so \ | |
/usr/local/lib/libopencv_highgui.so -o libcvjni.so \ | |
-I/usr/local/include -I/usr/lib/jvm/jdk1.6.0_35/include \ | |
-I/usr/lib/jvm/jdk1.6.0_35/include/linux |
NewerOlder