id stringlengths 36 36 | text stringlengths 1 1.25M |
|---|---|
78ec6f93-3e3c-4791-a445-93185d82fa16 | public void removeErrorListener(IErrorListener listener){
this.errorListeners.remove(listener);
} |
f64602cf-3662-4d9a-88fc-8a17277a155e | public void clearErrorListeners(){
this.errorListeners.clear();
} |
ad5e397a-b8c3-4985-8eee-127b55082993 | public List<Chromosome> getBreedPopulation() {
return breedPopulation;
} |
b0c0742b-9ca6-45a6-af68-76df7670827a | private SortOrder(){} |
283594a1-782c-4271-a643-ca731da5403c | public SortOrder(boolean ascending){
this.ascending = ascending;
} |
7b4e8e96-0642-490f-a4d9-bef4547a7e4c | @Override
public int compare(Chromosome o1, Chromosome o2) {
double val = 0.0;
if (this.ascending){
val = o1.getFitness() - o2.getFitness();
}else{
val = o2.getFitness() - o1.getFitness();
}
if(val > 0){
return 1;
}else if(val < 0){... |
88b83173-34e3-45ca-8ba4-66c020f0fddb | public GeoLocation(Location loc) {
this(loc.getLatitude(), loc.getLongitude());
} |
e7fd663c-6f5b-4c33-8612-7a0a4af4da83 | public GeoLocation(double latitude, double longitude) {
super();
this.latitude = latitude;
this.longitude = longitude;
} |
fe11731f-8849-4eda-9699-333cc931bf20 | @Override
public String toString() {
return "LAT=" + latitude + " LONG=" + longitude;
} |
0ce79cdd-d137-446c-bfdb-c25bf22174e6 | public RumpShaker(String serverUrl, RumpCallback callback) {
this(serverUrl, callback, new DefaultUICallback());
} |
ce393533-1d71-4f77-b431-f3703cc9861d | public RumpShaker(String serverUrl, RumpCallback callback, RumpUICallback uiCallback) {
this.client = new RumpClient(serverUrl);
this.callback = callback;
this.uiCallback = uiCallback;
} |
0198447f-a429-4bdd-a1ec-ee0c2b942f7f | public void start(Context context) {
this.sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
this.locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
this.context = context;
this.vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SE... |
666d6d7e-8968-49b2-9690-3b4348bd8cad | public void stop() {
locationManager.removeUpdates(locationListener);
sensorManager.unregisterListener(sensorListener);
client.discardBackgroundTasks();
} |
2571ccf8-f7fa-4f0b-a6ea-c34b667889d0 | private void onShake() {
long now = System.currentTimeMillis();
if (now - previousRequest < 3000) {
return;
}
previousRequest = now;
findCompany();
} |
b8b72b67-a2c4-4e79-9161-b7fc2a0032c2 | private void findCompany() {
vibrator.vibrate(100);
uiCallback.onRumpStart(context);
final RumpInfo myInfo = new RumpInfo(callback.getUsername(), callback.getDisplayName(), location);
client.rump(myInfo, new RumpResultHandler() {
public void onResponse(List<RumpInfo> dudes) {
uiCallback.onRumpEnd(context... |
aab20fa2-4037-466c-ab7b-9c1c1dc5591a | public void onResponse(List<RumpInfo> dudes) {
uiCallback.onRumpEnd(context);
gotCompany(dudes, myInfo);
} |
3ed32fbf-14cc-4861-94fa-2eefe3ed2906 | private void gotCompany(List<RumpInfo> dudes, RumpInfo me) {
Set<RumpInfo> uniqueUsers = newHashSet(dudes);
uniqueUsers.remove(me);
if (uniqueUsers.isEmpty()) {
uiCallback.onNoMatch(context);
} else {
int count = uniqueUsers.size();
longVibrations(vibrator, count);
uiCallback.onConnect(context, uniq... |
c744103e-c44a-46e8-ab5b-d2fcde07ec41 | private static void longVibrations(final Vibrator v, int count) {
long[] vibrations = new long[count * 2];
// First element is 0 => no delay
// Other elements are 300 => vibrate on/off every
// 300 ms to indicate number of friends
for (int i = 1; i < vibrations.length; i++) {
vibrations[i] = 300l;
}
v.... |
61f417b1-bb31-4508-a0a5-5287bbb42ee4 | public void onLocationChanged(Location androidLocation) {
location = new GeoLocation(androidLocation);
Log.i("RUMP Client", " got location " + location);
} |
2f9a6174-75a3-4bfc-83ef-dcd6a79b1ce9 | public void onStatusChanged(String provider, int status, Bundle extras) {
} |
f284f2e1-94b2-455e-8150-e8ea98ec3cbe | public void onProviderEnabled(String provider) {
} |
ec974e6f-079a-4e79-b014-8e7653a3135c | public void onProviderDisabled(String provider) {
} |
7fc2ef9b-1274-4380-8dc1-2b5493cf5b3e | public void onSensorChanged(SensorEvent se) {
float x = se.values[SensorManager.DATA_X];
float y = se.values[SensorManager.DATA_Y];
float z = se.values[SensorManager.DATA_Z];
if (prev != null) {
double diff = sqrt(sqr(x - prev[0]) + sqr(y - prev[1]) + sqr(z - prev[2]));
if (diff > 20) {
onShak... |
d94ed1af-cfb1-43e7-a4ce-02d6ddc9e281 | public void onAccuracyChanged(Sensor sensor, int accuracy) {
} |
d4638e36-677d-429c-a854-815b3a1185c1 | private float sqr(float a) {
return a * a;
} |
ea99c6f8-17cf-4085-9942-07818236a20c | public void onRumpStart(Context context) {
progressToast = Toast.makeText(context, "Looking for company..", Toast.LENGTH_LONG);
progressToast.show();
} |
7c2afa6d-99ca-4aa4-bc0e-c270932992cd | public void onRumpEnd(Context context) {
progressToast.cancel();
} |
2c297748-733a-484c-b5e3-40e1b762ebcb | public void onNoMatch(Context context) {
Toast.makeText(context, "No match", Toast.LENGTH_SHORT).show();
} |
aefaf87d-535e-40ce-8786-81d7d7807e67 | public void onConnect(Context context, Set<RumpInfo> uniqueUsers) {
Toast.makeText(context, "Found: " + Joiner.on(",").join(uniqueUsers), Toast.LENGTH_SHORT).show();
} |
40014b04-7b6e-462f-8f57-c5a268fd7655 | void onResponse(List<RumpInfo> result); |
75265b7a-4564-4380-9687-e3d4f194b725 | void onRumpStart(Context context); |
cbb80925-d573-4c5c-ac62-73e7e4d972a8 | void onRumpEnd(Context context); |
61ad22e1-53fe-4585-b4eb-aa1cdccebd06 | void onNoMatch(Context context); |
ca5c03ab-8c93-42ea-a197-4974e40bd268 | void onConnect(Context context, Set<RumpInfo> uniqueUsers); |
e45c1054-36a9-4f4a-bcba-d1883c5f6fad | public RumpInfo(String userId, String displayName, GeoLocation location) {
super();
this.userId = userId;
this.displayName = displayName;
this.location = location;
} |
c4da925b-2038-40b2-aadf-633a4be8669a | @Override
public String toString() {
return displayName;
} |
c060cfa6-fa44-4c7f-b3cf-469b7e0c94af | @Override
public boolean equals(Object o) {
return ((RumpInfo) o).userId.equals(userId);
} |
066a8d2d-87eb-4ffd-8902-8b1b034b0f13 | @Override
public int hashCode() {
return userId.hashCode();
} |
2e222a57-b251-4ea6-acd8-e592c62b2432 | String getUsername(); |
999b7d95-4e4e-4be0-b261-9f5a18c4a92f | String getDisplayName(); |
6b56b92c-7058-48c7-867e-0cbc3e84b980 | void connectedWith(Set<RumpInfo> uniqueUsers); |
fc4fd8ec-abf5-4f6b-935e-772a890a8204 | public RumpClient(String serverUrl) {
this.serverUrl = serverUrl;
} |
a10d29ad-176f-4a8e-943c-6bab12d45f72 | public void discardBackgroundTasks() {
pauseCount++;
} |
8f432edf-08e3-412a-8b3b-2141d59732af | public void rump(final RumpInfo myInfo, RumpResultHandler handler) {
new HttpMethod(handler, myInfo).execute();
} |
4171ada8-4efd-45c3-a27c-83b14735c047 | public HttpMethod(RumpResultHandler handler, RumpInfo myInfo) {
this.handler = handler;
this.myInfo = myInfo;
} |
ef8e6898-0c5c-40ea-ac83-d76f64fff383 | protected List<RumpInfo> post(final String url, final String requestBody) throws IOException {
Log.v("RUMP Client", "Executing http POST with body: " + requestBody);
HttpPost httpPost = new HttpPost(url);
StringEntity entity = new StringEntity(requestBody);
httpPost.setEntity(entity);
Type collectionType... |
54d6a74e-84c6-4106-9553-a90f541418eb | @Override
protected List<RumpInfo> doInBackground(String... params) {
try {
return method();
} catch (IOException e) {
Log.v("RUMP client", "http action failed", e);
throw new RumpCommunicationException(e);
}
} |
a186d8fd-91c1-4b7b-bd5e-6fd9cf4609d5 | @Override
protected void onPostExecute(List<RumpInfo> result) {
if (pauseCount == myPauseCount) {
handler.onResponse(result);
}
} |
54d0bf31-f91c-4663-9814-69f8851c3623 | protected List<RumpInfo> method() throws IOException {
try {
return post(serverUrl, new Gson().toJson(myInfo));
} catch (Exception e) {
return Collections.emptyList();
}
}; |
0f0bb019-398b-4ea2-ae0a-2f037a3217a3 | private <T> T executeHttpRequest(final HttpUriRequest request, final ValueExtractor<T> extractor) throws ClientProtocolException, IOException {
return httpClient().execute(request, new ResponseHandler<T>() {
public T handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
switch ... |
150f68bf-0cd5-48b0-923a-452e8e7079bf | public T handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
switch (response.getStatusLine().getStatusCode()) {
case 404:
throw new NotFoundException();
case 200:
BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(... |
39ab9f40-e363-4a30-ad05-3d7c87521604 | T extract(String s); |
01fff397-878a-426d-9fda-7ae60a168237 | private ListExtractor(Type t) {
this.t = t;
} |
d6477710-49da-4f58-9967-385ff48ab87d | static <T> ValueExtractor<List<T>> forClass(Class<T> k, Type t) {
return new ListExtractor<T>(t);
} |
fdfcf12a-9554-4431-a960-65dc82a9136d | public List<T> extract(String s) {
return new Gson().fromJson(s, t);
} |
2e35091a-52c6-48b7-ab7b-b4c3a3073c93 | private DefaultExtractor(Class<T> k) {
this.k = k;
} |
8eadc723-566a-44af-a33f-6eea84dea759 | static <T> ValueExtractor<T> forClass(Class<T> k) {
return new DefaultExtractor<T>(k);
} |
654babac-bd83-4bef-8484-4343ebfac286 | public T extract(String s) {
return new Gson().fromJson(s, k);
} |
6cfec845-fb94-498b-b3e4-c78feb6be074 | private DefaultHttpClient httpClient() {
if (httpClient == null) {
HttpParams params = createHttpParams();
SchemeRegistry registry = createSchemeRegistry();
ThreadSafeClientConnManager manager = new ThreadSafeClientConnManager(params, registry);
httpClient = new DefaultHttpClient(manager, params);
}
r... |
45fc7fb9-cfb7-452f-b6c9-a613ea078f4a | private SchemeRegistry createSchemeRegistry() {
SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
final SSLSocketFactory sslSocketFactory = SSLSocketFactory.getSocketFactory();
sslSocketFactory.setHostnameVerifier(SSLSocketFactory.B... |
7a4b5548-9feb-45f0-905c-f5a8f80a0531 | private HttpParams createHttpParams() {
HttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, "utf-8");
params.setBooleanParameter("http.protocol.expect-continue", false);
return params;
} |
78bc54ed-a1c3-4db8-9a59-cf109b3103e9 | public RumpCommunicationException(IOException e) {
super("Communication error with RUMP server.", e);
} |
f13a11fe-2fd1-453c-ae9b-526050479a3b | public void onData(Client client, ByteBuffer data, int bytesRead); |
a63b170b-4038-4fd6-8c75-ea3871f3df7f | public void onDisconnect(Client client); |
d12c70be-532f-46b6-9eac-3fb8a424f4ab | public void onConnected(Client client); |
69dc8acf-5f26-4906-ad15-48adb3302243 | public Client(SocketChannel socket, Selector selector, HashMap<SelectionKey, Client> clientsMap, SocketListener listener) {
mClientsMap = clientsMap;
mSocket = socket;
mSelector = selector;
mSocketListener = listener;
try{
register(SelectionKey.OP_READ);
mSocketListener.onConnected(this);
}catch(Ex... |
0146a3c9-f588-4958-8855-8fff84343899 | public void register(int op){
SelectionKey key = mSocket.keyFor(mSelector);
mClientsMap.remove(key);
SelectionKey keyNew = null;
try {
keyNew = mSocket.register(mSelector, op);
mClientsMap.put(keyNew, this);
} catch (ClosedChannelException e) {
disconnect();
}catch(Exception e){
e.printStackTrac... |
2acb2eb7-5540-4703-88cc-423ab07364f4 | public void write(ByteBuffer buffer){
mWriteBuffers.add(buffer);
register(SelectionKey.OP_READ | SelectionKey.OP_WRITE);
} |
a7353edd-183b-4559-8dae-7c0420636c68 | public boolean read() {
int read = 0;
boolean error = false;
java.nio.ByteBuffer bbuffer = java.nio.ByteBuffer.allocate(500);
try {
read = mSocket.read(bbuffer);
bbuffer.flip();
mSocketListener.onData(this, bbuffer, read);
} catch (Exception e) {
e.printStackTrace();
error = true;
}
if (re... |
c4d6c4e6-c1be-4633-9a66-09032e1d544b | public void disconnect(){
SelectionKey key = mSocket.keyFor(mSelector);
key.cancel();
try {
mSocket.socket().shutdownInput();
} catch (Exception e) {}
try {
mSocket.socket().shutdownOutput();
} catch (Exception e) {}
mSocketListener.onDisconnect(this);
} |
1d6983c9-bf43-4326-a2dd-190ec535c9b4 | public Socket(String host, int port, ClientSocketListener socketListener) throws IOException{
mSocketListener = socketListener;
mSelector = Selector.open();
mSocket = SocketChannel.open();
mSocket.configureBlocking(false);
mSocket.connect(new InetSocketAddress(host, port));
register(SelectionKey.OP_READ);
... |
b09ea19c-ed22-447e-8125-8399fbd823db | public void write(ByteBuffer buffer){
mWriteBuffers.add(buffer);
register(SelectionKey.OP_READ | SelectionKey.OP_WRITE);
} |
73662225-78b1-4005-80f5-f1f0b45e5cf2 | private void register(int op){
SelectionKey key = mSocket.keyFor(mSelector);
SelectionKey keyNew = null;
try {
keyNew = mSocket.register(mSelector, op);
} catch (ClosedChannelException e) {
disconnect();
}catch(Exception e){
e.printStackTrace();
}
if(key!=null && !key.equals(keyNew)){
key.c... |
472e8825-af6c-49bc-bc83-8ed230c91167 | public void disconnect(){
mSocketListener.onDisconnect(this);
try{
mSocket.socket().shutdownInput();
}catch(Exception e){
}
try{
mSocket.socket().shutdownOutput();
}catch(Exception e){
}
try {
mSocket.close();
} catch (IOException e) {
e.printStackTrace();
}
} |
acc3a410-3e85-41db-905e-e9a6f20ac861 | public Server(int port, SocketListener socketListener){
try {
mSocketListener = socketListener;
mSelector = Selector.open();
ServerSocketChannel server = ServerSocketChannel.open();
server.configureBlocking(false);
server.socket().bind(new InetSocketAddress(port));
server.register(mSelector, Selecti... |
c59c2c85-a62e-4ecc-8f3a-a537e6832491 | @Override
public void onData(Client client, ByteBuffer data, int bytesRead) {
mSocketListener.onData(client, data, bytesRead);
} |
3ea589dd-1a27-489f-b245-1dd073c5791c | @Override
public void onDisconnect(Client client) {
mClientsMap.remove(client.mSocket.keyFor(mSelector));
mSocketListener.onDisconnect(client);
} |
8b8fb267-211a-49d1-ae19-57551eee9f37 | @Override
public void onConnected(Client client) {
mClientsMap.put(client.mSocket.keyFor(mSelector), client);
mSocketListener.onConnected(client);
} |
181a6684-bdeb-4c24-a30a-9d1a9e2fdd9a | public void onData(Socket client, ByteBuffer data, int bytesRead); |
6e25e2ff-227f-48c2-b0bd-1f29e1af8c67 | public void onDisconnect(Socket client); |
b31ef0a0-9cff-4454-80fe-87972ceac801 | public void onConnected(Socket client); |
ca69ffa1-f23f-4168-ad3f-1ebfcb89e4ab | public Satellite(double x, double y, int sides) {
position = new Vector2(x, y);
velocity = new Vector2(Math.random(), Math.random());
facing = 0.0;
this.sides = sides;
radius = 50 * sides / 12;
// Create a hexagon
entityPolygon = new Polygon();
for (int ... |
8cb1a621-cb87-436e-8ae3-96910d6131f3 | public Satellite(Satellite source, BulletGenerator.Bullet killer) {
this(source.position.x, source.position.y, source.getSides() - 1);
velocity = source.velocity.copy();
Vector2 v = new Vector2(velocity.x, velocity.y);
v.rotateRad(killer.velocity.getAngleRad() + Math.random());
... |
e22ef2f5-bdda-4703-aceb-54ecf05ed1af | public boolean collided(Entity e) {
if (position.dist(e.position) >= radius * 2) { return false; }
return getShape().getBounds().intersects(e.getShape().getBounds());
} |
8e5c65ae-35d3-4748-abd7-5b1d0feef683 | public int getSides() { return sides; } |
744db7e6-1d73-406f-9218-fb027b4f08b6 | public final Vector2 getPosition() { return position; } |
1f8ff910-919f-4df3-b2f3-c4f7f0adb9b1 | public void draw(Graphics2D g) {
g.setColor(Color.WHITE);
facing += ROTATE_VALUE;
g.draw(getShape());
} |
578b39e1-f31a-4327-8a72-6b7c07732275 | private Keys(int key) { this.key = key; } |
12e2e1b2-ca1b-425a-acd0-6e9b0b5511f4 | public Ship(double x, double y) {
position = new Vector2(x, y);
velocity = new Vector2(0.0, 0.0);
facing = 0.0;
bGenerator = BulletGenerator.getInstance();
pGenerator = ParticleGenerator.getInstance();
entityPolygon = new Polygon(new int[]{0, -w / 2, w / 2}, new int[]{-... |
90e688de-791d-41a4-914e-83888a6674f9 | private void thrust() {
Vector2 acceleration = new Vector2(0.0, THRUST_VALUE);
acceleration.rotate(facing);
velocity.add(acceleration);
} |
96117c6b-cde3-446d-872c-bd16f1df2e0b | private void decelerate() {
if (!thrustersOn) {
velocity.x *= 0.99;
velocity.y *= 0.99;
}
} |
02140331-65da-4b55-9847-68a279f29331 | private void shoot() {
bGenerator.shootBullet(position.x, position.y, facing);
} |
18c75024-95f6-4341-b933-8ae2845dcebc | public void kill() {
dead = true;
// Explode!
ParticleGenerator.getInstance().generateExplosion(this);
} |
6d726dde-6a8a-4b15-acde-6fac5741261c | public boolean isDead() { return dead; } |
508e9859-c469-446d-8003-479858fbe48f | public final Vector2 getPosition() { return position; } |
eefac640-a38f-4cb8-951e-75e0f2f01b41 | public void tick() {
// Movement
switch (movement.getKey()) {
case LEFT:
facing -= ROTATE_VALUE;
break;
case RIGHT:
facing += ROTATE_VALUE;
break;
}
// Check trusters
if (thrustersOn) thrust(... |
4910f11d-e271-4f97-9c05-66355247fcd7 | public void move() {
if (!dead) {
super.move();
decelerate();
if (thrustersOn) {
// Generate a particle effect on the thrusters
Vector2 pPosition = position.copy();
Vector2 pVelocity = velocity.copy();
Vector2 a... |
de69c468-dd0b-43d8-9ed7-b4d00b7fe0e2 | public void draw(Graphics2D g) {
if (dead) return; // Don't draw if dead
g.setColor(Color.BLACK);
g.fill(getShape());
g.setColor(Color.WHITE);
g.draw(getShape());
if (thrustersOn) {
// Add a little flicker
int xp, yp;
xp = thrusterPol... |
59e199e7-6e2e-4d50-8765-a2c8241837b2 | public boolean collided(Entity e) { return false; } |
73942e74-45c0-49b0-88dd-d4dc3770d939 | @Override
public void keyPressed(KeyEvent e) {
switch(e.getKeyCode()){
case KeyEvent.VK_LEFT:
movement.setKey(Keys.LEFT);
break;
case KeyEvent.VK_RIGHT:
movement.setKey(Keys.RIGHT);
break;
case KeyEvent.VK_UP... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.