List of usage examples for java.util ArrayList set
public E set(int index, E element)
From source file:org.structr.core.entity.SchemaRelationshipNode.java
private void renameNameInNonGraphProperties(final AbstractSchemaNode schemaNode, final String toRemove, final String newValue) throws FrameworkException { // examine all views for (final SchemaView view : schemaNode.getSchemaViews()) { final String nonGraphProperties = view.getProperty(SchemaView.nonGraphProperties); if (nonGraphProperties != null) { final ArrayList<String> properties = new ArrayList<>( Arrays.asList(nonGraphProperties.split("[, ]+"))); final int pos = properties.indexOf(toRemove); if (pos != -1) { properties.set(pos, newValue); }/*from ww w. j a v a 2 s . c o m*/ view.setProperty(SchemaView.nonGraphProperties, StringUtils.join(properties, ", ")); } } }
From source file:nanowrimo.onishinji.adapter.SortableFragmentStatePagerAdapter.java
private void checkForIdChanges() { long[] newItemIds = new long[getCount()]; for (int i = 0; i < newItemIds.length; i++) { newItemIds[i] = getItemId(i);/*from w w w . j a va2 s.c o m*/ } if (!Arrays.equals(mItemIds, newItemIds)) { ArrayList<Fragment.SavedState> newSavedState = new ArrayList<Fragment.SavedState>(); ArrayList<Fragment> newFragments = new ArrayList<Fragment>(); for (int i = 0; i < newItemIds.length; i++) { newFragments.add(null); } for (int oldPosition = 0; oldPosition < mItemIds.length; oldPosition++) { int newPosition = POSITION_NONE; for (int i = 0; i < newItemIds.length; i++) { if (mItemIds[oldPosition] == newItemIds[i]) { newPosition = i; break; } } if (newPosition >= 0) { if (oldPosition < mSavedState.size()) { Fragment.SavedState savedState = mSavedState.get(oldPosition); if (savedState != null) { while (newSavedState.size() <= newPosition) { newSavedState.add(null); } newSavedState.set(newPosition, savedState); } } if (oldPosition < mFragments.size()) { Fragment fragment = mFragments.get(oldPosition); if (fragment != null) { while (newFragments.size() <= newPosition) { newFragments.add(null); } newFragments.set(newPosition, fragment); } } } } mItemIds = newItemIds; mSavedState = newSavedState; mFragments = newFragments; } }
From source file:jCMPL.CmplInstance.java
/** * Creates a CmplInstance string//from w ww .j av a 2s . c o m * * @param cmplFileName CMPL file * @param optList List of the options * @param dataString CmplData string * @param jobId JobId * @return CmplInstance string * @throws CmplException */ protected String cmplInstanceStr(String cmplFileName, HashMap<Integer, String> optList, String dataString, String jobId) throws CmplException { File cmplFile = new File(cmplFileName); if (cmplFile.exists()) { if (!dataString.isEmpty()) { _cmplDataList.put("__cmplData__" + cmplFile.getName().substring(0, cmplFile.getName().lastIndexOf('.')) + ".cdat", dataString); } } else { throw new CmplException("CMPL file " + cmplFileName + " does not exist."); } try { boolean commentSection = false; int lineNr = 0; BufferedReader in = new BufferedReader(new FileReader(cmplFileName)); String tmpName = ""; String tmpName1 = ""; ArrayList<String> lines = new ArrayList<String>(); String tmpLine = ""; while ((tmpLine = in.readLine()) != null) { lines.add(tmpLine); } in.close(); for (String line : lines) { line = line.trim(); if (line.startsWith("/*")) { commentSection = true; line = line.substring(0, line.indexOf("/*") - 1); } if (line.contains("*/")) { commentSection = false; line = line.substring(line.indexOf("*/") + 1); } if (commentSection) { continue; } if (line.startsWith("%data")) { if (line.contains(":")) { tmpName = line.substring(5, line.indexOf(":")).trim(); } else { tmpName = line.substring(5).trim(); } if (tmpName.isEmpty()) { if (!dataString.isEmpty()) { lines.set(lineNr, line.replace("%data", "%data __cmplData__" + cmplFile.getName().substring(0, cmplFile.getName().lastIndexOf('.')) + ".cdat")); tmpName = "__cmplData__"; } else { tmpName = cmplFile.getName().substring(0, cmplFile.getName().lastIndexOf('.')) + ".cdat"; } } if (!(_cmplDataList.containsKey(tmpName) || tmpName.equals("__cmplData__"))) { tmpName1 = ""; if (cmplFile.getParent() == null) { tmpName1 = cmplFile.getName().substring(0, cmplFile.getName().lastIndexOf('.')) + ".cdat"; } else { tmpName1 = cmplFile.getParent() + File.separator + cmplFile.getName().substring(0, cmplFile.getName().lastIndexOf('.')) + ".cdat"; } BufferedReader cin = new BufferedReader(new FileReader(tmpName1)); String dline = ""; String tmpString = ""; while ((dline = cin.readLine()) != null) { tmpString += dline; } cin.close(); _cmplDataList.put(tmpName1, tmpString); } } lineNr += 1; } _instStr.append("<?xml version = \"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"); _instStr.append("<CmplInstance version=\"1.0\">\n"); _instStr.append("<general>\n"); _instStr.append("<name>").append(cmplFile.getName()).append("</name>\n"); _instStr.append("<jobId>").append(jobId).append("</jobId>\n"); _instStr.append("</general>\n"); if (optList.size() > 0) { _instStr.append("<options>\n"); for (Map.Entry<Integer, String> o : optList.entrySet()) { _instStr.append("<opt>").append(o.getValue()).append("</opt>\n"); } _instStr.append("</options>\n"); } _instStr.append("<problemFiles>\n"); _instStr.append("<file name=\"").append(cmplFile.getName()).append("\" type=\"cmplMain\">\n"); String tmpStr = ""; for (String line : lines) { tmpStr += line + "\n"; } _instStr.append(StringEscapeUtils.escapeXml(tmpStr)); _instStr.append("\n"); _instStr.append("</file>\n"); for (Map.Entry<String, String> e : _cmplDataList.entrySet()) { _instStr.append("<file name=\"").append(e.getKey()).append("\" type=\"cmplData\">\n"); _instStr.append(StringEscapeUtils.escapeXml(e.getValue())); _instStr.append("\n"); _instStr.append("</file>\n"); } _instStr.append("</problemFiles>\n"); _instStr.append("</CmplInstance>\n"); } catch (IOException e ) { throw new CmplException("IO error : " + e); } return _instStr.toString(); }
From source file:org.sufficientlysecure.keychain.ui.keyview.loader.IdentityLoader.java
private void correlateOrAddTrustIds(ArrayList<IdentityInfo> identities) { Cursor cursor = contentResolver.query(ApiAutocryptPeer.buildByMasterKeyId(masterKeyId), TRUST_IDS_PROJECTION, null, null, null); if (cursor == null) { Log.e(Constants.TAG, "Error loading trust ids!"); return;//from w w w . j a v a 2s . c om } try { while (cursor.moveToNext()) { String packageName = cursor.getString(INDEX_PACKAGE_NAME); String autocryptPeer = cursor.getString(INDEX_TRUST_ID); Drawable drawable = packageIconGetter.getDrawableForPackageName(packageName); Intent autocryptPeerIntent = getTrustIdActivityIntentIfResolvable(packageName, autocryptPeer); UserIdInfo associatedUserIdInfo = findUserIdMatchingTrustId(identities, autocryptPeer); if (associatedUserIdInfo != null) { int position = identities.indexOf(associatedUserIdInfo); TrustIdInfo autocryptPeerInfo = TrustIdInfo.create(associatedUserIdInfo, autocryptPeer, packageName, drawable, autocryptPeerIntent); identities.set(position, autocryptPeerInfo); } else { TrustIdInfo autocryptPeerInfo = TrustIdInfo.create(autocryptPeer, packageName, drawable, autocryptPeerIntent); identities.add(autocryptPeerInfo); } } } finally { cursor.close(); } }
From source file:subsets.GenerateGFKMatrix.java
TreeMap<String, JSONObject> getDepTree_old(String query, ArrayList<String[]> hirarchy) { //staring on top graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(DB_PATH); registerShutdownHook(graphDb);/* ww w .j av a 2 s . co m*/ ExecutionEngine engine = new ExecutionEngine(graphDb); ExecutionResult result; TreeMap<String, JSONObject> name_json1 = new TreeMap(); TreeMap<String, JSONObject> name_json2 = new TreeMap(); try (Transaction ignored = graphDb.beginTx()) { result = (ExecutionResult) engine.execute(query);//"MATCH (sc:SmartCube)<-[:MEMBER_OF]-(sca:SCAttribut) RETURN sc,sca" TreeMap<String, HashSet> O2_O3 = new TreeMap(); TreeMap<String, HashSet> O1_O2 = new TreeMap(); for (Map<String, Object> row : result) { ArrayList<String> objects = new ArrayList(); for (int i = 0; i < hirarchy.size(); i++) objects.add(""); for (Entry<String, Object> column : row.entrySet()) { Node x = (Node) column.getValue(); for (int i = 0; i < hirarchy.size(); i++) { String[] object_property = hirarchy.get(i); if (column.getKey().equals(object_property[0])) { //System.out.println(x.getProperty(object_property[1])); objects.set(i, (String) x.getProperty(object_property[1])); } } } addAttribute_to_Treemap(objects.get(0), objects.get(1), O1_O2); addAttribute_to_Treemap(objects.get(1), objects.get(2), O2_O3); } //ende query part_tree(O2_O3, null, name_json1, true); part_tree(O1_O2, name_json1, name_json2, false); ignored.success(); } graphDb.shutdown(); return name_json2; }
From source file:com.hygenics.parser.ForceConformity.java
private void iter() { log.info("Starting Enforcement @ " + Calendar.getInstance().getTime().toString() + " | UTC " + Calendar.getInstance().getTimeInMillis()); String sql;//w w w .j a v a 2 s.c o m boolean add = true; ArrayList<String> columns = null; ArrayList<String> tablecolumns = null; Quicksort<String> qs = new Quicksort<String>(); Levenshtein lev = new Levenshtein(); // iterate through each table for (String table : schema_columns.keySet()) { log.info("Checking for Table Existance " + table); String schema = null; try { schema = table.split("\\.")[0]; } catch (IndexOutOfBoundsException e) { try { throw new SQLMalformedException("FATAL ERROR: Table name " + table + " malformed"); } catch (SQLMalformedException e2) { e2.printStackTrace(); System.exit(-1); } } log.info("Checking table: " + table + "&& schema: " + schema); if (template.checkTable(table, schema)) { log.info("Conforming: " + table); // get the arraylist tablecolumns = template.getColumns(table); if (insensitive == true) { for (int i = 0; i < tablecolumns.size(); i++) { tablecolumns.set(i, tablecolumns.get(i).toLowerCase()); } } columns = (ArrayList<String>) schema_columns.get(table); if (insensitive == true) { for (int i = 0; i < columns.size(); i++) { columns.set(i, columns.get(i).toLowerCase()); } } if (exclude != null) { // remove unmatchable columns if (exclude.size() > 0) { for (String col : exclude) { tablecolumns.remove(col); columns.remove(col); } } } // sort each arraylist qs.setTosortlist(columns); columns = qs.sort(); qs.setTosortlist(tablecolumns); tablecolumns = qs.sort(); // check each remaining column for (int i = 0; i < columns.size(); i++) { if (tablecolumns.contains(columns.get(i).trim()) == false || (insensitive == true && tablecolumns.contains(columns.get(i).toLowerCase().trim()) == false)) { if (correct) { int dist = Levenshtein.getLevenshteinDistance(tablecolumns.get(i), columns.get(i)); add = false; log.info("Distance was " + dist + " Cutoff is " + levcutoff); // check lev. distances if requested and ensure some // match with fuzzy (use at your own risk) if (levcutoff > -1 & dist <= levcutoff) { log.info("Approximate Match: Correcting Column"); // if distance is within 1 or specified // distances, correct it sql = "ALTER TABLE " + table + " RENAME COLUMN " + tablecolumns.get(i) + " TO " + columns.get(i); template.execute(sql); // get the table columns tablecolumns = template.getColumns(table); qs.setTosortlist(tablecolumns); tablecolumns = qs.sort(); } else { add = true; } } if (add) { // add column if necessary sql = "Alter Table " + table + " ADD COLUMN " + columns.get(i) + " text"; template.execute(sql); // get the table columns again and resort them tablecolumns = template.getColumns(table); if (exclude != null) { if (exclude.size() > 0) { for (String ex : exclude) { tablecolumns.remove(ex); columns.remove(ex); } } } qs.setTosortlist(tablecolumns); tablecolumns = qs.sort(); } // iterate backward so that the integrety is assured i--; } } } else { try { throw new SQLMalformedException("WARNING: Table " + table + " is missing"); } catch (SQLMalformedException e) { e.printStackTrace(); } } } log.info("Finishing Enforcement @ " + Calendar.getInstance().getTime().toString() + " | UTC " + Calendar.getInstance().getTimeInMillis()); }
From source file:nl.mpcjanssen.simpletask.AddTask.java
private void replacePriority(@NotNull CharSequence newPrio) { // save current selection and length int start = textInputField.getSelectionStart(); int end = textInputField.getSelectionEnd(); Log.v(TAG, "Current selection: " + start + "-" + end); int length = textInputField.getText().length(); int sizeDelta; ArrayList<String> lines = new ArrayList<String>(); Collections.addAll(lines, textInputField.getText().toString().split("\\n", -1)); // For some reason the currentLine can be larger than the amount of lines in the EditText // Check for this case to prevent any array index out of bounds errors int currentLine = getCurrentCursorLine(textInputField); if (currentLine > lines.size() - 1) { currentLine = lines.size() - 1;// w ww . j a v a2s.com } if (currentLine != -1) { Task t = new Task(0, lines.get(currentLine)); Log.v(TAG, "Changing prio from " + t.getPriority().toString() + " to " + newPrio.toString()); t.setPriority(Priority.toPriority(newPrio.toString())); lines.set(currentLine, t.inFileFormat()); textInputField.setText(Util.join(lines, "\n")); } // restore selection int newLength = textInputField.getText().length(); sizeDelta = newLength - length; int newStart = Math.max(0, start + sizeDelta); int newEnd = Math.min(end + sizeDelta, newLength); newEnd = Math.max(newStart, newEnd); Log.v(TAG, "New selection (" + sizeDelta + "): " + newStart + "-" + newEnd); textInputField.setSelection(newStart, newEnd); }
From source file:subsets.GenerateGFKMatrix.java
TreeMap<String, JSONObject> getDepTree(String query, ArrayList<String[]> hirarchy) { //staring on top graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(DB_PATH); registerShutdownHook(graphDb);//from w w w . j av a 2 s .co m ExecutionEngine engine = new ExecutionEngine(graphDb); ExecutionResult result; TreeMap<String, JSONObject> name_json = new TreeMap(); try (Transaction ignored = graphDb.beginTx()) { result = (ExecutionResult) engine.execute(query);//"MATCH (sc:SmartCube)<-[:MEMBER_OF]-(sca:SCAttribut) RETURN sc,sca" ArrayList<TreeMap<String, HashSet>> head_tail = new ArrayList(); for (int j = 0; j < hirarchy.size() - 1; j++) { TreeMap<String, HashSet> dummy = new TreeMap(); head_tail.add(dummy); } //TreeMap<String,HashSet> O2_O3 = new TreeMap(); //TreeMap<String,HashSet> O1_O2 = new TreeMap(); for (Map<String, Object> row : result) { ArrayList<String> objects = new ArrayList(); for (int i = 0; i < hirarchy.size(); i++) objects.add(""); for (Entry<String, Object> column : row.entrySet()) { Node x = (Node) column.getValue(); for (int i = 0; i < hirarchy.size(); i++) { String[] object_property = hirarchy.get(i); if (column.getKey().equals(object_property[0])) { //System.out.println(x.getProperty(object_property[1])); objects.set(i, (String) x.getProperty(object_property[1])); } } } for (int j = 0; j < hirarchy.size() - 1; j++) addAttribute_to_Treemap(objects.get(j), objects.get(j + 1), head_tail.get(j)); // addAttribute_to_Treemap(objects.get(0),objects.get(1),O1_O2); // addAttribute_to_Treemap(objects.get(1),objects.get(2),O2_O3); } //ende query for (int j = 0; j < hirarchy.size() - 1; j++) { if (j == hirarchy.size() - 1) { part_tree(head_tail.get(j), name_json, name_json, false); } else { part_tree(head_tail.get(j), null, name_json, true); } } ignored.success(); } graphDb.shutdown(); return name_json; }
From source file:com.ichi2.libanki.Models.java
private Object[] _reqForTemplate(JSONObject m, ArrayList<String> flds, JSONObject t) { try {//from w w w . j av a 2 s .co m ArrayList<String> a = new ArrayList<String>(); ArrayList<String> b = new ArrayList<String>(); for (String f : flds) { a.add("ankiflag"); b.add(""); } Object[] data; data = new Object[] { 1l, 1l, m.getLong("id"), 1l, t.getInt("ord"), "", Utils.joinFields(a.toArray(new String[a.size()])) }; String full = mCol._renderQA(data).get("q"); data = new Object[] { 1l, 1l, m.getLong("id"), 1l, t.getInt("ord"), "", Utils.joinFields(b.toArray(new String[b.size()])) }; String empty = mCol._renderQA(data).get("q"); // if full and empty are the same, the template is invalid and there is no way to satisfy it if (full.equals(empty)) { return new Object[] { "none", new JSONArray(), new JSONArray() }; } String type = "all"; JSONArray req = new JSONArray(); ArrayList<String> tmp = new ArrayList<String>(); for (int i = 0; i < flds.size(); i++) { tmp.clear(); tmp.addAll(a); tmp.set(i, ""); data[6] = Utils.joinFields(tmp.toArray(new String[tmp.size()])); // if no field content appeared, field is required if (!mCol._renderQA(data).get("q").contains("ankiflag")) { req.put(i); } } if (req.length() > 0) { return new Object[] { type, req }; } // if there are no required fields, switch to any mode type = "any"; req = new JSONArray(); for (int i = 0; i < flds.size(); i++) { tmp.clear(); tmp.addAll(b); tmp.set(i, "1"); data[6] = Utils.joinFields(tmp.toArray(new String[tmp.size()])); // if not the same as empty, this field can make the card non-blank if (!mCol._renderQA(data).get("q").equals(empty)) { req.put(i); } } return new Object[] { type, req }; } catch (JSONException e) { throw new RuntimeException(e); } }
From source file:com.chinamobile.bcbsp.graph.GraphDataForDisk.java
/** * Set the bitmap's bit for the hashIndex hash bucket's nodeIndex headnode to * be 1./* www .j ava2 s.com*/ * @param hashIndex int * @param nodeIndex int * @param aBitmaps */ private void setBitmapTrue(int hashIndex, int nodeIndex, ArrayList<ArrayList<Integer>> aBitmaps) { // Get the refered bitmap of the bucket. ArrayList<Integer> bitmap = aBitmaps.get(hashIndex); // The node bit belongs to the point int element of the array. int point = nodeIndex / 32; // If the nodeIndex over the bitmap's size, append new 32 bit. if ((point + 1) > bitmap.size()) { bitmap.add(new Integer(0)); } // The bit shift number for the int element. int shift = 31 - nodeIndex % 32; // The unit for the int element to or. int orUnit = 1; orUnit = orUnit << shift; // Or the int element with the unit to set the bit to 1. bitmap.set(point, bitmap.get(point) | orUnit); // Set back the bitmap into the bucket. aBitmaps.set(hashIndex, bitmap); }