public synchronized Auftrag checkNeighborfields(Vector2Int position) { for (Neighborcase neighborcase : Neighborcase.values()) { for (Auftrag auf : this) { Vector2Int test = (Vector2Int) position.copy().add(neighborcase.getVector()); if (auf.gibZiel().equals(test)) { this.remove(auf); return auf; } } } return null; }
/** * Gibt den Auftrag zurueck, der am naechsten an der uebergebenen Position ist * * @param position Position, in deren Naehe der Auftrag sein soll * @return Naechster Auftrag */ public synchronized Auftrag gibNaechsten(Vector2Int position) { Auftrag tmpauftrag = null; if (size() > 0) { Vector1Double dist = new Vector1Double(200000.0); for (Auftrag auf : this) { Vector2Int ziel = auf.gibZiel(); Vector1Double tmpdist = (Vector1Double) ziel.getDistance(position); if (tmpdist.less(dist)) { dist = tmpdist; tmpauftrag = auf; } } this.remove(tmpauftrag); } else { } return tmpauftrag; }
public Sync(JSONArray jAuftr, DBHandler db, String server) { try { // Verbindung zum Server herstellen URL url = new URL(server); HttpURLConnection con = (HttpURLConnection) url.openConnection(); // post Variable an JSON-Array übergeben String data = "data=" + jAuftr; con.setDoOutput(true); con.setInstanceFollowRedirects(true); con.setRequestMethod("POST"); con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); con.setRequestProperty("charset", "UTF-8"); con.setUseCaches(false); OutputStreamWriter out = new OutputStreamWriter(con.getOutputStream()); // Daten an Server posten out.write(data); out.close(); JSONArray mJsonArray = new JSONArray(readStream(con.getInputStream()).replace('"', '\"')); JSONObject mJsonObject; for (int i = 0; i < mJsonArray.length(); i++) { mJsonObject = mJsonArray.getJSONObject(i); Auftrag auftrag = new Auftrag(); auftrag.setPrio(mJsonObject.getString("prio").toString()); auftrag.setKat(mJsonObject.getString("kategorie").toString()); auftrag.setDatum(mJsonObject.getString("datum").toString()); auftrag.setBeschreibung(mJsonObject.getString("beschreibung").toString()); auftrag.setRaum(mJsonObject.getString("beschreibung").toString()); db.addAuftrag(auftrag); } } catch (Exception e) { e.printStackTrace(); } }