List of usage examples for java.util ArrayList remove
public boolean remove(Object o)
From source file:com.evvsoft.treeview.SimpleJsonTreeViewAdapter.java
private TreeViewNodeArray convertToTreeJSONArray(JSONArray data) throws JSONException { TreeViewNodeArray result = new TreeViewNodeArray(); ArrayList<Integer> notHandled = new ArrayList<Integer>(); for (int i = 0; i < data.length(); i++) { JSONObject obj = data.getJSONObject(i); if (!(putChild(result, obj))) // Parent node not found, may be, it has not yet added notHandled.add(i);/*from w w w. j ava 2 s . c o m*/ } // Now try again to add more items Boolean prevAdded = true; while (prevAdded && (notHandled.size() > 0)) { prevAdded = false; for (int i = 0; i < notHandled.size();) { JSONObject obj = data.getJSONObject(notHandled.get(i)); if (putChild(result, obj)) { prevAdded = true; notHandled.remove(i); } else i++; } } // Forget items with id_parent pointing to nonexistent parents return result; }
From source file:bkampfbot.modes.Jagd.java
public void run() { Output.printClockLn("Wrterjagd", 1); int availablePoints; int score;/*from w w w .j a va2 s. c o m*/ try { do { JSONObject result = Utils.getJSON("games/getWheelData"); JSONArray data = result.getJSONArray("data"); availablePoints = result.getJSONArray("credit").getJSONObject(0).getInt("highscore"); score = result.getJSONArray("credit").getJSONObject(0).getInt("sloganhighscore"); Output.printTabLn("Aktuelle Punktzahl: " + availablePoints, 2); if (data.length() != 5) { Output.println("Etwas stimmt nicht. Abbruch.", Output.ERROR); } for (int i = 0; i < 5 && availablePoints > 20 && score < percent && doMore(); i++) { JSONObject current = data.getJSONObject(i); Output.printTab(names[i] + ": ", Output.DEBUG); if (current.getInt("result") == 1) { Output.println(" erledigt", Output.DEBUG); continue; } Output.println(" zu lsen", Output.DEBUG); if (letterMax > 0) { ArrayList<Character> alpha = new ArrayList<Character>(); for (int j = 65; j < 65 + 26; j++) { alpha.add((char) j); } // check for letters for (int z = 0; z < letterMax; z++) { if (availablePoints < current.getInt("costletter")) { return; } if (z >= letterMin && Math.random() > 0.4) { continue; } int currentAlpha = (new Random()).nextInt(alpha.size() - 1); char currentLetter = alpha.get(currentAlpha); alpha.remove(currentAlpha); Output.printTabLn("Kaufe ein " + currentLetter, Output.INFO); List<NameValuePair> nvps = new ArrayList<NameValuePair>(); nvps.add(new BasicNameValuePair("buyletter", currentLetter + "")); nvps.add(new BasicNameValuePair("type", "letter")); Utils.getString("games/buyWheel", nvps); availablePoints -= current.getInt("costletter"); Control.sleep(45); } } String md5; try { String dec = decrypt(current.getJSONArray("slogan")); Output.printTab(dec + ": ", Output.INFO); SimpleFile.append("Jagd." + names[i] + ".txt", dec + "\n"); MessageDigest m = MessageDigest.getInstance("MD5"); byte[] data1 = ("OsShlljuozll11T670OO00OO" + dec.replaceAll("\\s", "")).getBytes(); m.update(data1, 0, data1.length); BigInteger in = new BigInteger(1, m.digest()); md5 = String.format("%1$032X", in); } catch (NoSuchAlgorithmException e) { Output.error(e); return; } md5 = md5.toLowerCase(); List<NameValuePair> nvpn = new ArrayList<NameValuePair>(); nvpn.add(new BasicNameValuePair("type", "slogan")); nvpn.add(new BasicNameValuePair("secret", md5)); Control.sleep(new Random().nextInt(100) + 100); String res = Utils.getString("games/buyWheel", nvpn); if (res.equals("errorStatus=ok&right=right")) { Output.println("richtig", Output.INFO); score++; wordsSolved++; } else { Output.println("falsch", Output.INFO); break; } availablePoints -= 20; } // Auf gut Glck -klicken if (score >= percent && luck) { int level = 0; if (score >= 100) { level = 100; } else if (score >= 75) { level = 75; } else if (score >= 50) { level = 50; } else if (score >= 20) { level = 20; } else if (score >= 10) { level = 10; } if (level > 0) { Control.sleep(40, Output.INFO); // errorStatus=ok&modus=item&item_pic=wurf387.png&item_type=ring&wintext=Teekessel+mit+ohrenbet%C3%A4ubender+Pfeife String line = Utils.getString("games/payout"); Map<String, String> para = Utils.getUrlParameters(line); if (para.get("modus").equals("item")) { Output.printClockLn("Gewinn: " + para.get("item_type") + ", " + para.get("wintext"), Output.INFO); } else if (para.get("modus").equals("trost")) { Output.printClockLn("Gewinn: " + para.get("wintext") + " " + para.get("preis"), Output.INFO); } else { Output.println(para.toString(), Output.INFO); } score -= level; } } } while (availablePoints > 20 && score < percent && doMore()); } catch (JSONException e) { Output.error(e); return; } }
From source file:eu.europa.esig.dss.cades.signature.CadesLevelBaselineLTATimestampExtractor.java
/** * The field unsignedAttrsHashIndex is a sequence of octet strings. Each one contains the hash value of one * instance of Attribute within unsignedAttrs field of the SignerInfo. A hash value for every instance of * Attribute, as present at the time when the corresponding archive time-stamp is requested, shall be included in * unsignedAttrsHashIndex. No other hash values shall be included in this field. * * We check that every hash attribute found in the timestamp token is found if the signerInformation. * * If there is more unsigned attributes in the signerInformation than present in the hash attributes list * (and there is at least the archiveTimestampAttributeV3), we don't report any error nor which attributes are signed by the timestamp. * If there is some attributes that are not present or altered in the signerInformation, we just return some empty sequence to make * sure that the timestamped data will not match. We do not report which attributes hash are present if any. * * If there is not attribute at all in the archive timestamp hash index, that would means we didn't check anything. * * @param signerInformation/*from w ww . java 2 s. c o m*/ * @param timestampToken * @return */ @SuppressWarnings("unchecked") private ASN1Sequence getVerifiedUnsignedAttributesHashIndex(SignerInformation signerInformation, TimestampToken timestampToken) throws DSSException { final ASN1Sequence unsignedAttributesHashes = getUnsignedAttributesHashIndex(timestampToken); final ArrayList<DEROctetString> timestampUnsignedAttributesHashesList = Collections .list(unsignedAttributesHashes.getObjects()); AttributeTable unsignedAttributes = CMSUtils.getUnsignedAttributes(signerInformation); final ASN1EncodableVector asn1EncodableVector = unsignedAttributes.toASN1EncodableVector(); for (int i = 0; i < asn1EncodableVector.size(); i++) { final Attribute attribute = (Attribute) asn1EncodableVector.get(i); final DEROctetString derOctetStringDigest = getAttributeDerOctetStringHash(attribute); final ASN1ObjectIdentifier attrType = attribute.getAttrType(); if (timestampUnsignedAttributesHashesList.remove(derOctetStringDigest)) { // attribute present in signature and in timestamp LOG.debug("Attribute {} present in timestamp", attrType.getId()); } else { LOG.debug("Attribute {} not present in timestamp", attrType.getId()); } } if (!timestampUnsignedAttributesHashesList.isEmpty()) { LOG.error("{} attribute hash in Timestamp have not been found in document attributes: {}", timestampUnsignedAttributesHashesList.size(), timestampUnsignedAttributesHashesList); // return a empty DERSequence to screw up the hash return new DERSequence(); } // return the original DERSequence return unsignedAttributesHashes; }
From source file:com.esri.core.geometry.OperatorImportFromGeoJsonLocal.java
@Override public MapOGCStructure executeOGC(int import_flags, String geoJsonString, ProgressTracker progress_tracker) throws JSONException { JSONObject geoJsonObject = new JSONObject(geoJsonString); ArrayList<OGCStructure> structureStack = new ArrayList<OGCStructure>(0); ArrayList<JSONObject> objectStack = new ArrayList<JSONObject>(0); AttributeStreamOfInt32 indices = new AttributeStreamOfInt32(0); AttributeStreamOfInt32 numGeometries = new AttributeStreamOfInt32(0); OGCStructure root = new OGCStructure(); root.m_structures = new ArrayList<OGCStructure>(0); structureStack.add(root); // add dummy root objectStack.add(geoJsonObject);//from ww w . j a va2s .c o m indices.add(0); numGeometries.add(1); while (!objectStack.isEmpty()) { if (indices.getLast() == numGeometries.getLast()) { structureStack.remove(structureStack.size() - 1); indices.removeLast(); numGeometries.removeLast(); continue; } OGCStructure lastStructure = structureStack.get(structureStack.size() - 1); JSONObject lastObject = objectStack.get(objectStack.size() - 1); objectStack.remove(objectStack.size() - 1); indices.write(indices.size() - 1, indices.getLast() + 1); String typeString = lastObject.getString("type"); if (typeString.equalsIgnoreCase("GeometryCollection")) { OGCStructure next = new OGCStructure(); next.m_type = 7; next.m_structures = new ArrayList<OGCStructure>(0); lastStructure.m_structures.add(next); structureStack.add(next); JSONArray geometries = getJSONArray(lastObject, "geometries"); indices.add(0); numGeometries.add(geometries.length()); for (int i = geometries.length() - 1; i >= 0; i--) objectStack.add(geometries.getJSONObject(i)); } else { int ogcType; if (typeString.equalsIgnoreCase("Point")) ogcType = 1; else if (typeString.equalsIgnoreCase("LineString")) ogcType = 2; else if (typeString.equalsIgnoreCase("Polygon")) ogcType = 3; else if (typeString.equalsIgnoreCase("MultiPoint")) ogcType = 4; else if (typeString.equalsIgnoreCase("MultiLineString")) ogcType = 5; else if (typeString.equalsIgnoreCase("MultiPolygon")) ogcType = 6; else throw new UnsupportedOperationException(); Geometry geometry = importGeometryFromGeoJson_(import_flags, Geometry.Type.Unknown, lastObject); OGCStructure leaf = new OGCStructure(); leaf.m_type = ogcType; leaf.m_geometry = geometry; lastStructure.m_structures.add(leaf); } } MapOGCStructure mapOGCStructure = new MapOGCStructure(); mapOGCStructure.m_ogcStructure = root; mapOGCStructure.m_spatialReference = importSpatialReferenceFromGeoJson_(geoJsonObject); return mapOGCStructure; }
From source file:com.headwire.aem.tooling.intellij.communication.ServerConnectionManager.java
private String checkBundleVersion(String version) { String ret = ""; // Versions need to be in this format n.n.n(-|_)aaaaa where n is a number and a are alphanumeric characters // If a version number is missing we need to add and superfluous numbers need to be removed int separator = version.indexOf('-'); if (separator < 0) { separator = version.indexOf("-"); }/*from ww w. ja v a2s .c o m*/ String qualifier = ""; if (separator >= 0) { qualifier = "." + (separator < version.length() - 1 ? version.substring(separator + 1) : ""); version = version.substring(0, separator); } String[] tokens = version.split("\\."); ArrayList<String> tokenList = new ArrayList<String>(Arrays.asList(tokens)); while (tokenList.size() < 3) { tokenList.add("0"); } while (tokenList.size() > 3) { tokenList.remove(tokenList.size() - 1); } // Build version for (String token : tokenList) { ret += token + "."; } ret = ret.substring(0, ret.length() - 1); ret += qualifier; return ret; }
From source file:com.tremolosecurity.provisioning.core.providers.AlfrescoProviderREST.java
@Override public void syncUser(User user, boolean addOnly, Set<String> attributes, Map<String, Object> request) throws ProvisioningException { int approvalID = 0; if (request.containsKey("APPROVAL_ID")) { approvalID = (Integer) request.get("APPROVAL_ID"); }/* w ww. j av a2s. c om*/ Workflow workflow = (Workflow) request.get("WORKFLOW"); String token = ""; try { token = this.login(); } catch (Exception e) { throw new ProvisioningException("Could not initialize Alfresco Web Services Client", e); } AlfrescoUser userDetails; try { userDetails = userLookup(user.getUserID(), token); } catch (Exception e) { this.createUser(user, attributes, request); return; } for (String attrName : user.getAttribs().keySet()) { Attribute attr = user.getAttribs().get(attrName); if (!attributes.contains(attr.getName())) { continue; } StringBuffer b = new StringBuffer(); b.append("set").append(attrName.toUpperCase().charAt(0)).append(attrName.substring(1)); String methodName = b.toString(); try { Method method = AlfrescoUser.class.getMethod(methodName, String.class); method.invoke(userDetails, attr.getValues().get(0)); } catch (Exception e) { throw new ProvisioningException("Could not create user", e); } } Gson gson = new Gson(); String json = gson.toJson(userDetails, AlfrescoUser.class); StringBuffer b = new StringBuffer(); b.append(this.endpoint).append("/people/").append(user.getUserID()).append("?alf_ticket=").append(token); HttpPut httpput = new HttpPut(b.toString()); try { LastMileUtil.addLastMile(cfg, loginId, HEADER_NAME, httpput, lastMileKeyAlias, useLastMile); } catch (Exception e) { throw new ProvisioningException("Error generating provisioning last mile", e); } //httpput.addHeader("X-Alfresco-Remote-User", this.loginId); try { StringEntity data = new StringEntity(json); data.setContentType("application/json"); httpput.setEntity(data); try { CloseableHttpResponse response = httpclient.execute(httpput); if (response.getStatusLine().getStatusCode() != 200) { throw new Exception("error"); } response.close(); } finally { httpput.releaseConnection(); } } catch (Exception e) { throw new ProvisioningException("Could not sync user", e); } for (String attrName : user.getAttribs().keySet()) { Attribute attr = user.getAttribs().get(attrName); if (!attributes.contains(attr.getName())) { continue; } this.cfg.getProvisioningEngine().logAction(this.name, false, ActionType.Replace, approvalID, workflow, attrName, user.getAttribs().get(attrName).getValues().get(0)); } ArrayList<String> tmpgroups = new ArrayList<String>(); tmpgroups.addAll(user.getGroups()); List<String> groups = null; try { groups = this.groupUserGroups(user.getUserID(), token); } catch (Exception e1) { throw new ProvisioningException("Could not load groups", e1); } if (groups != null) { for (String group : groups) { if (tmpgroups.contains(group)) { tmpgroups.remove(group); } else { if (!addOnly) { this.deleteUserFromGroup(token, user.getUserID(), group, approvalID, workflow); } } } for (String group : tmpgroups) { this.addUsertoGroup(token, user.getUserID(), group, approvalID, workflow); } } }
From source file:com.photon.phresco.impl.AndroidDevicesParameterImpl.java
public PossibleValues getValues(Map<String, Object> map) throws IOException, ParserConfigurationException, SAXException, ConfigurationException, PhrescoException { ArrayList<String> devices = new ArrayList<String>(); try {/* ww w . j a va 2 s.co m*/ String s = null; Process p = Runtime.getRuntime().exec(CMD_ADB_DEVICES); BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream())); BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream())); int cnt = 0; while ((s = stdInput.readLine()) != null) { if (cnt > 0) { s = s.substring(0, s.indexOf("\t") + 1); devices.add(s.trim()); } cnt++; } stdInput.close(); cnt = 0; while ((s = stdError.readLine()) != null) { if (cnt > 0) { s = s.substring(0, s.indexOf("\t") + 1); devices.add(s.trim()); } cnt++; } stdError.close(); } catch (Exception e) { // Error in retriving connected devices } PossibleValues possibleValues = new PossibleValues(); if (CollectionUtils.isNotEmpty(devices)) { devices.remove(devices.size() - 1); for (String device : devices) { Value value = new Value(); value.setValue(device); possibleValues.getValue().add(value); } } return possibleValues; }
From source file:gov.nih.nci.caintegrator.application.gpvisualizer.CaIntegratorRunVisualizer.java
protected String[] doCommandLineSubstitutions() throws IOException { // do input argument substitution in command line String commandLine = (String) params.get(RunVisualizerConstants.COMMAND_LINE); HashMap hmDownloadables = downloadInputURLs(); StringTokenizer stCmd = new StringTokenizer(commandLine, " "); ArrayList cmdArray = new ArrayList(stCmd.countTokens()); int c = 0;//w w w .ja v a2s . c o m while (stCmd.hasMoreTokens()) { cmdArray.add(stCmd.nextToken()); } // replace variables in the command line from System.properties and the // params HashMap for (c = 0; c < cmdArray.size(); c++) { String cmd = (String) cmdArray.get(c); cmd = variableSubstitution(cmd, hmDownloadables); cmdArray.set(c, cmd); // if there is nothing in a slot after substitutions, delete the // slot entirely if (cmd.length() == 0) { cmdArray.remove(c); c--; } } cmdArray.trimToSize(); return (String[]) cmdArray.toArray(new String[0]); }
From source file:jeplus.data.ParameterItem.java
/** * Combining the two lists or excluding the second list from the first. * @param vals1 The first list/* w ww . j a v a2 s.c om*/ * @param vals2 The second list * @param op Operation can be either COMBINE or EXCLUDE * @return a new list as the combination of the two */ private String[] mergeLists(String[] vals1, String[] vals2, int op, boolean allow_duplicates) { ArrayList<String> set = new ArrayList(Arrays.asList(vals1)); if (op == COMBINE) { for (int i = 0; i < vals2.length; i++) { if (allow_duplicates || !set.contains(vals2[i])) set.add(vals2[i]); } } else { for (int i = 0; i < vals2.length; i++) { set.remove(vals2[i]); } } return set.toArray(new String[0]); }
From source file:com.kaltura.playersdk.PlayerViewController.java
public void removeKPlayerEventListener(String eventName, String callbackName) { ArrayList<KPlayerEventListener> listeners = mKplayerEventsMap.get(eventName); if (listeners != null) { for (int i = 0; i < listeners.size(); i++) { if (listeners.get(i).getCallbackName().equals(callbackName)) { listeners.remove(i); break; }/*from w ww . j av a 2s . c o m*/ } if (listeners.size() == 0) notifyKPlayer("removeJsListener", new String[] { eventName }); } }