List of usage examples for java.util ArrayList set
public E set(int index, E element)
From source file:com.clust4j.utils.VectorTests.java
@Test public void testDeepClone() { ArrayList<Double> og = new ArrayList<>(); og.add(0.0);// w w w.j av a 2s . co m ArrayList<Double> co = VecUtils.copy(og); co.set(0, 1.0); assertFalse(og.get(0) == 1.0); }
From source file:com.gawdl3y.android.tasktimer.adapters.NewFragmentStatePagerAdapter.java
@Override public void notifyDataSetChanged() { int[] newItemIds = new int[getCount()]; for (int i = 0; i < newItemIds.length; i++) { newItemIds[i] = getItemId(i);//from ww w .jav a2s . c om } if (!Arrays.equals(mItemIds, newItemIds)) { ArrayList<Fragment.SavedState> newSavedState = new ArrayList<Fragment.SavedState>(); ArrayList<Fragment> newFragments = new ArrayList<Fragment>(); 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; } super.notifyDataSetChanged(); }
From source file:com.krawler.common.util.StringUtil.java
public static String filterQuery(ArrayList filter_names, String appendCase) { StringBuilder filterQuery = new StringBuilder(); // String filterQuery = ""; String oper = ""; String op = ""; for (int i = 0; i < filter_names.size(); i++) { if (filter_names.get(i).toString().length() >= 5) op = filter_names.get(i).toString().substring(0, 5); if (op.equals("ISNOT")) { oper = " is not "; String opstr = filter_names.get(i).toString(); filter_names.set(i, opstr.substring(5, opstr.length())); } else if (op.equals("NOTIN")) { oper = " not in(" + i + ")"; String opstr = filter_names.get(i).toString(); filter_names.set(i, opstr.substring(5, opstr.length())); } else {/* w w w .j a v a 2s .c o m*/ if (filter_names.get(i).toString().length() >= 4) op = filter_names.get(i).toString().substring(0, 4); if (op.equals("LIKE")) { oper = " like "; String opstr = filter_names.get(i).toString(); filter_names.set(i, opstr.substring(4, opstr.length())); } else { op = filter_names.get(i).toString().substring(0, 2); if (op.equals("<=")) { oper = " <= "; String opstr = filter_names.get(i).toString(); filter_names.set(i, opstr.substring(2, opstr.length())); } else if (op.equals(">=")) { oper = " >= "; String opstr = filter_names.get(i).toString(); filter_names.set(i, opstr.substring(2, opstr.length())); } else if (op.equals("IS")) { oper = " is "; String opstr = filter_names.get(i).toString(); filter_names.set(i, opstr.substring(2, opstr.length())); } else if (op.equals("IN")) { oper = " in (" + i + ") "; String opstr = filter_names.get(i).toString(); filter_names.set(i, opstr.substring(2, opstr.length())); } else { op = filter_names.get(i).toString().substring(0, 1); if (op.equals("!")) { oper = " != "; String opstr = filter_names.get(i).toString(); filter_names.set(i, opstr.substring(1, opstr.length())); } else if (op.equals("<")) { oper = " < "; String opstr = filter_names.get(i).toString(); filter_names.set(i, opstr.substring(1, opstr.length())); } else if (op.equals(">")) { oper = " > "; String opstr = filter_names.get(i).toString(); filter_names.set(i, opstr.substring(1, opstr.length())); } else oper = " = "; } } } if (i == 0) { // filterQuery += " where "+filter_names.get(i)+" = ? "; if (!op.equals("IN") && !op.equals("NOTIN")) filterQuery.append(" " + appendCase + " " + filter_names.get(i) + oper + " ? "); else filterQuery.append(" " + appendCase + " " + filter_names.get(i) + oper); } else { // filterQuery += " and "+filter_names.get(i)+" = ? "; if (!op.equals("IN") && !op.equals("NOTIN")) filterQuery.append(" and " + filter_names.get(i) + oper + " ? "); else filterQuery.append(" and " + " " + filter_names.get(i) + oper); } } return filterQuery.toString(); }
From source file:version1.Neo4jTest.Neo4jQuery.java
TreeMap<String, JSONObject> getDepTree_old(String query, ArrayList<String[]> hirarchy) { //staring on top graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(DB_PATH); registerShutdownHook(graphDb);//w w w . j a v a2s.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.example.newfragmentstatepageradapter.NewFragmentStatePagerAdapter.java
@Override public void notifyDataSetChanged() { long[] newItemIds = new long[getCount()]; for (int i = 0; i < newItemIds.length; i++) { newItemIds[i] = getItemId(i);//w w w . j a va 2 s . co m } if (!Arrays.equals(mItemIds, newItemIds)) { ArrayList<Fragment.SavedState> newSavedState = new ArrayList<Fragment.SavedState>(); ArrayList<Fragment> newFragments = new ArrayList<Fragment>(); 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; } super.notifyDataSetChanged(); }
From source file:org.apache.axis2.jaxws.utility.JavaUtils.java
/** * @param Namespace//from w w w . jav a 2 s .c om * @param apend underscore to keyword * @return String representing Namespace */ public static String getPackageFromNamespace(String namespace, boolean appendUnderscoreToKeyword) { // The following steps correspond to steps described in the JAXB Specification if (log.isDebugEnabled()) { log.debug("namespace (" + namespace + ")"); } // Step 1: Scan off the host name String hostname = null; String path = null; try { URL url = new URL(namespace); hostname = url.getHost(); path = url.getPath(); } catch (MalformedURLException e) { // No FFDC code needed // If a MalformedURLException occurs, then // just simply get one string and put it in the hostname. // In such cases the path will remain empty. // This code is necessary so that we can process namespaces // like "urn:acme" or simply "sampleNamespace" if (namespace.indexOf(":") > -1) { // Brain-dead code to skip over the protocol hostname = namespace.substring(namespace.indexOf(":") + 1); } else { hostname = namespace; } } if (log.isDebugEnabled()) { log.debug("hostname (" + hostname + ")"); log.debug("path (" + path + ")"); } // Step 3: Tokenize the host name using ":" and "/" StringTokenizer st = new StringTokenizer(hostname, ":/"); ArrayList<String> wordList = new ArrayList<String>(); //Read Hostname first. while (st != null && st.hasMoreTokens()) { wordList.add(st.nextToken()); } //Read rest Of the path now if (path != null) { StringTokenizer pathst = new StringTokenizer(path, "/"); while (pathst != null && pathst.hasMoreTokens()) { wordList.add(pathst.nextToken()); } } String[] words = wordList.toArray(new String[0]); // Now do step 2: Strip off the trailing "." (i.e. strip off .html) if (words != null && words.length > 1) { String lastWord = words[words.length - 1]; int index = lastWord.lastIndexOf('.'); if (index > 0) { words[words.length - 1] = lastWord.substring(0, index); } } // Step 4: Unescape each escape sequence // TODO I don't know what to do here. // Step 5: If protocol is urn, replace - with . in the first word if (namespace.startsWith("urn:")) { words[0] = replace(words[0], "-", "."); } // Step 6: Tokenize the first word with "." and reverse the order. (the www is also removed). // TODO This is not exactly equivalent to the JAXB Rule. ArrayList<String> list = new ArrayList<String>(); if (words.length > 0) { StringTokenizer st2 = new StringTokenizer(words[0], "."); while (st2.hasMoreTokens()) { // Add the strings so they are in reverse order list.add(0, st2.nextToken()); } } // Remove www if (list.size() > 0) { String last = list.get(list.size() - 1); if (last.equals("www")) { list.remove(list.size() - 1); } } // Now each of words is represented by list for (int i = 1; i < words.length; i++) { list.add(words[i]); } // Step 7: lowercase each word for (int i = 0; i < list.size(); i++) { String word = list.remove(i); word = word.toLowerCase(); list.add(i, word); } // Step 8: make into and an appropriate java word for (int i = 0; i < list.size(); i++) { String word = list.get(i); // 8a: Convert special characters to underscore // Convert non-java words to underscore. // TODO: Need to do this for all chars..not just hyphens word = replace(word, "-", "_"); // 8b: Append _ to java keywords if (JavaUtils.isJavaKeyword(word)) { if (appendUnderscoreToKeyword) { word = word + "_"; // This is defined by the JAXB Spec } else { word = "_" + word; // Apparently wsimport can generate this style } } // 8c: prepend _ if first character cannot be the first character of a java identifier if (!Character.isJavaIdentifierStart(word.charAt(0))) { word = "_" + word; } list.set(i, word); } // Step 9: Concatenate and return String name = ""; for (int i = 0; i < list.size(); i++) { if (i == 0) { name = list.get(0); } else { name = name + "." + list.get(i); } } if (log.isDebugEnabled()) { log.debug("package name (" + name + ")"); } return name; }
From source file:version1.Neo4jTest.Neo4jQuery.java
TreeMap<String, JSONObject> getDepTree(String query, ArrayList<String[]> hirarchy) { //staring on top graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(DB_PATH); registerShutdownHook(graphDb);//from w ww. j a v a 2 s . c om 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:edu.usf.cutr.fdot7.io.IndividualCsvEntityReader.java
/** * Read data and convert it to the appropriate data for inserting purpose * @param line//from w w w . j a va 2 s.c o m */ private void readEntity(List<String> line) { if (line.size() != _fields.size()) { _log.warn("expected and actual number of csv fields differ: type=" + _entity + " line # " + _line + " expected=" + _fields.size() + " actual=" + line.size()); while (line.size() < _fields.size()) line.add(""); } ArrayList<Object> v = new ArrayList<Object>(); if (_entity.equals("shapes")) { for (int i = 0; i < line.size(); i++) { v.add(line.get(i)); } data.addGtfsData(v); } else { //initialize arraylist v for (int i = 0; i < fdSchema.getFields().size(); i++) { v.add(null); } for (int i = 0; i < line.size(); i++) { String field = _fields.get(i); String value = line.get(i); int indexFdot = -1; if (mapping.get(field) != null) indexFdot = new Integer(mapping.get(field)); if (indexFdot != -1) { if (value.equals("")) { emptyFields.add(field); continue; } Object valueWithType = getValueWithCorrectType(indexFdot, value); v.set(indexFdot, valueWithType); } else noMatchFields.add(field); } if (_entity.equals("stops")) { double wgsLatLon[] = new double[2]; wgsLatLon[0] = Double.parseDouble((String) line.get(_fields.indexOf("stop_lon"))); wgsLatLon[1] = Double.parseDouble((String) line.get(_fields.indexOf("stop_lat"))); CoordSystemPointConversion conversion = new CoordSystemPointConversion( "PROJCS[\"Albers Conical Equal Area [Florida Geographic Data Library]\"," + "GEOGCS[\"GCS_North_American_1983_HARN\"," + "DATUM[\"D_North_American_1983_HARN\"," + "SPHEROID[\"GRS_1980\",6378137.0,298.257222101]]," + "PRIMEM[\"Greenwich\",0.0]," + "UNIT[\"Degree\",0.0174532925199433]]," + "PROJECTION[\"Albers\"]," + "PARAMETER[\"False_Easting\",400000.0]," + "PARAMETER[\"False_Northing\",0.0]," + "PARAMETER[\"Central_Meridian\",-84.0]," + "PARAMETER[\"Standard_Parallel_1\",24.0]," + "PARAMETER[\"Standard_Parallel_2\",31.5]," + "PARAMETER[\"Central_Parallel\",24.0]," + "UNIT[\"Meter\",1.0]]"); double projLatLon[] = new double[2]; projLatLon = conversion.getConversionOf(wgsLatLon); SDEPoint[] pts = new SDEPoint[] { new SDEPoint(projLatLon[0], projLatLon[1]) }; v.set(v.size() - 1, pts); } data.addGtfsData(v); } }
From source file:com.kevinread.sortablefragmentpager.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.jav a 2s . c om*/ } if (!Arrays.equals(mItemIds, newItemIds)) { ArrayList<Fragment.SavedState> newSavedState = new ArrayList<Fragment.SavedState>(); ArrayList<Fragment> newFragments = new ArrayList<Fragment>(); 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:com.btmura.android.reddit.app.FragmentStateItemPagerAdapter.java
@Override public void notifyDataSetChanged() { long[] newItemIds = new long[getCount()]; for (int i = 0; i < newItemIds.length; i++) { newItemIds[i] = getItemId(i);/*w w w . j a v a 2 s . c o m*/ } if (!Arrays.equals(mItemIds, newItemIds)) { ArrayList<Fragment.SavedState> newSavedState = new ArrayList<Fragment.SavedState>(); ArrayList<Fragment> newFragments = new ArrayList<Fragment>(); int numItemIds = mItemIds != null ? mItemIds.length : 0; for (int oldPosition = 0; oldPosition < numItemIds; 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; } super.notifyDataSetChanged(); }