List of usage examples for java.util ArrayList remove
public boolean remove(Object o)
From source file:User_Manager.User_TblJDBCTemplate.java
public boolean follow_Unfollow(int loggedin_user, int profile_user, int cmd) throws SQLException { /* //from w w w . j a v a2 s. c om follower- is the logged in user sending request to follow/unfollow followed- is the user who follower wants to follow or unfollow */ try { con = conn.getDataSource().getConnection(); PreparedStatement st = con.prepareStatement( "SELECT A.following,B.followers FROM login_tbl A, login_tbl B where A.uid=? and B.uid=?;"); st.setInt(1, loggedin_user); st.setInt(2, profile_user); ResultSet rs = st.executeQuery(); rs.next(); ArrayList<Integer> profile_user_followers = gson.fromJson(rs.getString("followers"), ArrayList.class); ArrayList<Integer> loggedin_user_following = gson.fromJson(rs.getString("following"), ArrayList.class); switch (cmd) { case 0: {//unfollow profile_user_followers.remove(loggedin_user + .0); loggedin_user_following.remove(profile_user + .0); // } break; case 1: {//follow profile_user_followers.add(loggedin_user); loggedin_user_following.add(profile_user); } break; } // IMPORTANT Make a transaction or a batch execution here st = con.prepareStatement("UPDATE login_tbl SET following=? WHERE uid=?;"); st.setObject(1, loggedin_user_following.toString()); st.setObject(2, loggedin_user); //System.out.println("query for following"+st); st.execute(); //st.addBatch(); st = con.prepareStatement("UPDATE login_tbl SET followers=? WHERE uid=?;"); st.setObject(1, profile_user_followers.toString()); st.setObject(2, profile_user); //System.out.println("query for followers"+st); st.execute(); //st.addBatch(); //int rslt[]=st.executeBatch(); return true; } catch (Exception e) { return false; } finally { con.close(); } }
From source file:com.celements.calendar.Event.java
void splitLanguageDependentFields(Set<String> confIndep, Set<String> confDep, List<String> propertyNames) { ArrayList<String> propNamesCleanList = new ArrayList<String>(); propNamesCleanList.addAll(propertyNames); propNamesCleanList.remove("detaillink"); if (propNamesCleanList.contains("date") || propNamesCleanList.contains("time")) { propNamesCleanList.remove("date"); propNamesCleanList.remove("time"); propNamesCleanList.add("eventDate"); }/* w ww . ja v a 2s . c om*/ if (propNamesCleanList.contains("date_end") || propNamesCleanList.contains("time_end")) { propNamesCleanList.remove("date_end"); propNamesCleanList.remove("time_end"); propNamesCleanList.add("eventDate_end"); } LOGGER.debug("splitLanguageDepFields: " + propNamesCleanList.toString()); for (String propName : propNamesCleanList) { if (propName.startsWith("l_")) { confDep.add(propName); } else { confIndep.add(propName); } } }
From source file:com.blm.orc.OrcRawRecordMerger.java
@Override public ObjectInspector getObjectInspector() { // Read the configuration parameters String columnNameProperty = conf.get(serdeConstants.LIST_COLUMNS); // NOTE: if "columns.types" is missing, all columns will be of String type String columnTypeProperty = conf.get(serdeConstants.LIST_COLUMN_TYPES); // Parse the configuration parameters ArrayList<String> columnNames = new ArrayList<String>(); Deque<Integer> virtualColumns = new ArrayDeque<Integer>(); if (columnNameProperty != null && columnNameProperty.length() > 0) { String[] colNames = columnNameProperty.split(","); for (int i = 0; i < colNames.length; i++) { if (VirtualColumn.VIRTUAL_COLUMN_NAMES.contains(colNames[i])) { virtualColumns.addLast(i); } else { columnNames.add(colNames[i]); }// ww w . j a va 2 s .c o m } } if (columnTypeProperty == null) { // Default type: all string StringBuilder sb = new StringBuilder(); for (int i = 0; i < columnNames.size(); i++) { if (i > 0) { sb.append(":"); } sb.append("string"); } columnTypeProperty = sb.toString(); } ArrayList<TypeInfo> fieldTypes = TypeInfoUtils.getTypeInfosFromTypeString(columnTypeProperty); while (virtualColumns.size() > 0) { fieldTypes.remove(virtualColumns.removeLast()); } StructTypeInfo rowType = new StructTypeInfo(); rowType.setAllStructFieldNames(columnNames); rowType.setAllStructFieldTypeInfos(fieldTypes); return OrcRecordUpdater.createEventSchema(OrcStruct.createObjectInspector(rowType)); }
From source file:eu.europa.esig.dss.cades.signature.CadesLevelBaselineLTATimestampExtractor.java
private boolean handleCrlEncoded(ArrayList<DEROctetString> crlHashesList, byte[] crlHolderEncoded) { final byte[] digest = DSSUtils.digest(hashIndexDigestAlgorithm, crlHolderEncoded); final DEROctetString derOctetStringDigest = new DEROctetString(digest); return crlHashesList.remove(derOctetStringDigest); }
From source file:eu.europa.esig.dss.cades.signature.CadesLevelBaselineLTATimestampExtractor.java
private void handleRevocationEncoded(ArrayList<DEROctetString> crlHashesList, byte[] ocspHolderEncoded) { final byte[] digest = DSSUtils.digest(hashIndexDigestAlgorithm, ocspHolderEncoded); final DEROctetString derOctetStringDigest = new DEROctetString(digest); if (crlHashesList.remove(derOctetStringDigest)) { // attribute present in signature and in timestamp if (LOG.isDebugEnabled()) { LOG.debug("CRL/OCSP present in timestamp {}", DSSUtils.toHex(derOctetStringDigest.getOctets())); }/*from www. j ava2 s. c om*/ } else { if (LOG.isDebugEnabled()) { LOG.debug("CRL/OCSP not present in timestamp {}", DSSUtils.toHex(derOctetStringDigest.getOctets())); } } }
From source file:edu.isi.karma.view.VWorksheet.java
private void deleteHeaderViewPath(ArrayList<VHNode> nodes, String path) { int idx = path.indexOf("/"); String pathStart = path, pathEnd = null; if (idx != -1) { pathStart = path.substring(0, idx); pathEnd = path.substring(idx + 1); }//from w ww. j a v a 2 s .com for (VHNode node : nodes) { if (node.getNodePathSignature().equals(pathStart)) { if (pathEnd == null) { nodes.remove(node); } else { deleteHeaderViewPath(node.getNestedNodes(), pathEnd); } break; } } }
From source file:info.varden.anatychia.Main.java
public static MaterialDataList materialList(SaveData save, ProgressUpdater pu, MaterialData[] filters) { Random random = new Random(); boolean filtersNull = filters == null; pu.updated(0, 1);/*from w w w. j a v a2 s.c om*/ pu.updated(-3, 1); MaterialDataList mdl = new MaterialDataList(); File saveDir = save.getLocation(); File[] regionFolders = listRegionContainers(saveDir); int depth = Integer.MAX_VALUE; File shallowest = null; for (File f : regionFolders) { String path = f.getAbsolutePath(); Pattern p = Pattern.compile(Pattern.quote(File.separator)); Matcher m = p.matcher(path); int count = 0; while (m.find()) { count++; } if (count < depth) { depth = count; if (shallowest == null || f.getName().equalsIgnoreCase("region")) { shallowest = f; } } } pu.updated(-1, 1); ArrayList<File> regions = new ArrayList<File>(); int tfs = 0; for (File f : regionFolders) { String dimName = f.getParentFile().getName(); boolean deleted = false; if (f.equals(shallowest)) { dimName = "DIM0"; } if (!filtersNull) { for (MaterialData type : filters) { if (type.getType() == MaterialType.DIMENSION && type.getName().equals(dimName)) { System.out.println("Deleting: " + dimName); deleted = recursiveDelete(f); } } } if (deleted) continue; mdl.increment(new MaterialData(MaterialType.DIMENSION, dimName, 1L)); File[] r = f.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return name.endsWith(".mca"); } }); int max = r.length; int cur = 0; for (File valid : r) { cur++; try { BufferedInputStream bis = new BufferedInputStream(new FileInputStream(valid)); byte[] offsetHeader = new byte[4096]; bis.read(offsetHeader, 0, 4096); bis.close(); ByteBuffer bb = ByteBuffer.wrap(offsetHeader); IntBuffer ib = bb.asIntBuffer(); while (ib.remaining() > 0) { if (ib.get() != 0) { tfs++; } } bb = null; ib = null; } catch (IOException ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } // tfs += Math.floor(valid.length() / 1000D); pu.updated(cur, max); } regions.addAll(Arrays.asList(r)); } if (regions.size() <= 0) { pu.updated(1, 1); return mdl; } pu.updated(-2, 1); int fc = 0; int fs = 0; for (File region : regions) { fc++; //fs += Math.floor(region.length() / 1000D); try { RegionFile anvil = new RegionFile(region); for (int x = 0; x < 32; x++) { for (int z = 0; z < 32; z++) { InputStream is = anvil.getChunkDataInputStream(x, z); if (is == null) continue; NBTInputStream nbti = new NBTInputStream(is, CompressionMode.NONE); CompoundTag root = (CompoundTag) nbti.readTag(); String rootName = root.getName(); CompoundTag level = (CompoundTag) root.getValue().get("Level"); Map<String, Tag> levelTags = level.getValue(); ListTag sectionTag = (ListTag) levelTags.get("Sections"); ArrayList<Tag> sections = new ArrayList<Tag>(sectionTag.getValue()); for (int i = 0; i < sections.size(); i++) { mdl.setSectorsRelative(1); CompoundTag sect = (CompoundTag) sections.get(i); Map<String, Tag> sectTags = sect.getValue(); ByteArrayTag blockArray = (ByteArrayTag) sectTags.get("Blocks"); byte[] add = new byte[0]; boolean hasAdd = false; if (sectTags.containsKey("Add")) { hasAdd = true; ByteArrayTag addArray = (ByteArrayTag) sectTags.get("Add"); add = addArray.getValue(); } byte[] blocks = blockArray.getValue(); for (int j = 0; j < blocks.length; j++) { short id; byte aid = (byte) 0; if (hasAdd) { aid = ChunkFormat.Nibble4(add, j); id = (short) ((blocks[j] & 0xFF) + (aid << 8)); } else { id = (short) (blocks[j] & 0xFF); } if (!filtersNull) { for (MaterialData type : filters) { if (type.getType() == MaterialType.BLOCK && type.getName().equals(String.valueOf(blocks[j] & 0xFF)) && (type.getRemovalChance() == 1D || random.nextDouble() < type.getRemovalChance())) { blocks[j] = (byte) 0; if (aid != 0) { add[j / 2] = (byte) (add[j / 2] & (j % 2 == 0 ? 0xF0 : 0x0F)); } id = (short) 0; } } } mdl.increment(new MaterialData(MaterialType.BLOCK, String.valueOf(id), 1L)); } if (!filtersNull) { HashMap<String, Tag> rSectTags = new HashMap<String, Tag>(); rSectTags.putAll(sectTags); ByteArrayTag bat = new ByteArrayTag("Blocks", blocks); rSectTags.put("Blocks", bat); if (hasAdd) { ByteArrayTag adt = new ByteArrayTag("Add", add); rSectTags.put("Add", adt); } CompoundTag rSect = new CompoundTag(sect.getName(), rSectTags); sections.set(i, rSect); } } ListTag entitiesTag = (ListTag) levelTags.get("Entities"); ArrayList<Tag> entities = new ArrayList<Tag>(entitiesTag.getValue()); for (int i = entities.size() - 1; i >= 0; i--) { CompoundTag entity = (CompoundTag) entities.get(i); Map<String, Tag> entityTags = entity.getValue(); if (entityTags.containsKey("id")) { StringTag idTag = (StringTag) entityTags.get("id"); String id = idTag.getValue(); boolean removed = false; if (!filtersNull) { for (MaterialData type : filters) { if (type.getType() == MaterialType.ENTITY && (type.getName().equals(id) || type.getName().equals("")) && (type.getRemovalChance() == 1D || random.nextDouble() < type.getRemovalChance())) { if (type.fulfillsRequirements(entity)) { entities.remove(i); removed = true; } } } } if (!removed) { mdl.increment(new MaterialData(MaterialType.ENTITY, id, 1L)); } } } nbti.close(); is.close(); if (!filtersNull) { HashMap<String, Tag> rLevelTags = new HashMap<String, Tag>(); rLevelTags.putAll(levelTags); ListTag rSectionTag = new ListTag("Sections", CompoundTag.class, sections); rLevelTags.put("Sections", rSectionTag); ListTag rEntityTag = new ListTag("Entities", CompoundTag.class, entities); rLevelTags.put("Entities", rEntityTag); final CompoundTag rLevel = new CompoundTag("Level", rLevelTags); HashMap<String, Tag> rRootTags = new HashMap<String, Tag>() { { put("Level", rLevel); } }; CompoundTag rRoot = new CompoundTag(rootName, rRootTags); OutputStream os = anvil.getChunkDataOutputStream(x, z); NBTOutputStream nbto = new NBTOutputStream(os, CompressionMode.NONE); nbto.writeTag(rRoot); nbto.close(); } fs++; pu.updated(fs, tfs); } } anvil.close(); } catch (Exception ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } } MaterialData[] data = mdl.toArray(); System.out.println("FILES SCANNED: " + fc); for (MaterialData d : data) { System.out.println(d.getType().getName() + ": " + d.getName() + " (" + d.getQuantity() + ")"); } return mdl; }
From source file:com.hichinaschool.flashcards.libanki.Stats.java
/** * Reps and time spent/*from w w w .j av a 2 s . c om*/ * *********************************************************************************************** */ public boolean calculateDone(int type, boolean reps) { mType = type; mBackwards = true; if (reps) { mTitle = R.string.stats_review_count; mAxisTitles = new int[] { type, R.string.stats_answers }; } else { mTitle = R.string.stats_review_time; } mValueLabels = new int[] { R.string.statistics_learn, R.string.statistics_relearn, R.string.statistics_young, R.string.statistics_mature, R.string.statistics_cram }; mColors = new int[] { R.color.stats_learn, R.color.stats_relearn, R.color.stats_young, R.color.stats_mature, R.color.stats_cram }; int num = 0; int chunk = 0; switch (type) { case TYPE_MONTH: num = 31; chunk = 1; break; case TYPE_YEAR: num = 52; chunk = 7; break; case TYPE_LIFE: num = -1; chunk = 30; break; } ArrayList<String> lims = new ArrayList<String>(); if (num != -1) { lims.add("id > " + ((mCol.getSched().getDayCutoff() - ((num + 1) * chunk * 86400)) * 1000)); } String lim = _revlogLimit().replaceAll("[\\[\\]]", ""); if (lim.length() > 0) { lims.add(lim); } if (lims.size() > 0) { lim = "WHERE "; while (lims.size() > 1) { lim += lims.remove(0) + " AND "; } lim += lims.remove(0); } else { lim = ""; } String ti; String tf; if (!reps) { ti = "time/1000"; if (mType == 0) { tf = "/60.0"; // minutes mAxisTitles = new int[] { type, R.string.stats_minutes }; } else { tf = "/3600.0"; // hours mAxisTitles = new int[] { type, R.string.stats_hours }; } } else { ti = "1"; tf = ""; } ArrayList<double[]> list = new ArrayList<double[]>(); Cursor cur = null; try { cur = mCol.getDb().getDatabase() .rawQuery("SELECT (cast((id/1000 - " + mCol.getSched().getDayCutoff() + ") / 86400.0 AS INT))/" + chunk + " AS day, " + "sum(CASE WHEN type = 0 THEN " + ti + " ELSE 0 END)" + tf + ", " // lrn + "sum(CASE WHEN type = 1 AND lastIvl < 21 THEN " + ti + " ELSE 0 END)" + tf + ", " // yng + "sum(CASE WHEN type = 1 AND lastIvl >= 21 THEN " + ti + " ELSE 0 END)" + tf + ", " // mtr + "sum(CASE WHEN type = 2 THEN " + ti + " ELSE 0 END)" + tf + ", " // lapse + "sum(CASE WHEN type = 3 THEN " + ti + " ELSE 0 END)" + tf // cram + " FROM revlog " + lim + " GROUP BY day ORDER BY day", null); while (cur.moveToNext()) { list.add(new double[] { cur.getDouble(0), cur.getDouble(1), cur.getDouble(4), cur.getDouble(2), cur.getDouble(3), cur.getDouble(5) }); } } finally { if (cur != null && !cur.isClosed()) { cur.close(); } } // small adjustment for a proper chartbuilding with achartengine if (type != TYPE_LIFE && (list.size() == 0 || list.get(0)[0] > -num)) { list.add(0, new double[] { -num, 0, 0, 0, 0, 0 }); } else if (type == TYPE_LIFE && list.size() == 0) { list.add(0, new double[] { -12, 0, 0, 0, 0, 0 }); } if (list.get(list.size() - 1)[0] < 0) { list.add(new double[] { 0, 0, 0, 0, 0, 0 }); } mSeriesList = new double[6][list.size()]; for (int i = 0; i < list.size(); i++) { double[] data = list.get(i); mSeriesList[0][i] = data[0]; // day mSeriesList[1][i] = data[1] + data[2] + data[3] + data[4] + data[5]; // lrn mSeriesList[2][i] = data[2] + data[3] + data[4] + data[5]; // relearn mSeriesList[3][i] = data[3] + data[4] + data[5]; // young mSeriesList[4][i] = data[4] + data[5]; // mature mSeriesList[5][i] = data[5]; // cram } return list.size() > 0; }
From source file:net.ontopia.topicmaps.utils.MergeUtils.java
private static boolean equals(TMObjectIF obj1, TMObjectIF obj2) { // can't be topics, or we wouldn't be here if (obj1 instanceof AssociationIF && obj2 instanceof AssociationIF) { AssociationIF a1 = (AssociationIF) obj1; AssociationIF a2 = (AssociationIF) obj2; if (a1.getType() == a2.getType() && a1.getRoles().size() == a2.getRoles().size() && a1.getScope().equals(a2.getScope())) { ArrayList<AssociationRoleIF> roles2 = new ArrayList<AssociationRoleIF>(a2.getRoles()); Iterator<AssociationRoleIF> it1 = a1.getRoles().iterator(); while (it1.hasNext()) { AssociationRoleIF role1 = it1.next(); Iterator<AssociationRoleIF> it2 = roles2.iterator(); boolean found = false; while (it2.hasNext()) { AssociationRoleIF role2 = it2.next(); if (role2.getPlayer() == role1.getPlayer() && role1.getType() == role2.getType()) { roles2.remove(role2); found = true;//from w ww . j a va 2 s .c o m break; } } if (!found) break; } return roles2.isEmpty(); } } else if (obj1 instanceof TopicNameIF && obj2 instanceof TopicNameIF) { TopicNameIF bn1 = (TopicNameIF) obj1; TopicNameIF bn2 = (TopicNameIF) obj2; return (bn1.getTopic().equals(bn2.getTopic()) && sameAs(bn1.getValue(), bn2.getValue()) && sameAs(bn1.getType(), bn2.getType()) && sameAs(bn1.getScope(), bn2.getScope())); } else if (obj1 instanceof OccurrenceIF && obj2 instanceof OccurrenceIF) { OccurrenceIF occ1 = (OccurrenceIF) obj1; OccurrenceIF occ2 = (OccurrenceIF) obj2; return (occ1.getTopic().equals(occ2.getTopic()) && sameAs(occ1.getValue(), occ2.getValue()) && sameAs(occ1.getDataType(), occ2.getDataType()) && sameAs(occ1.getType(), occ2.getType()) && sameAs(occ1.getScope(), occ2.getScope())); } return false; }
From source file:com.microsoft.tfs.util.PlatformVersion.java
/** * Returns the integer components of the given version number string. * "Components" are defined as any non-alphanumeric separated string of * alphanumeric characters. Only the integer components are returned and * only up to a non-integer component. For example, given the * "10_4.21Q.Z.14", the return will be [ 10, 4, 21 ]. * * @param versionString//from ww w. j a va 2 s .c o m * The version number string * @return An integer array of the numeric components of the version number * string */ static final int[] parseVersionNumber(final String versionString) { if (versionString == null || versionString.length() == 0) { return new int[0]; } /* * Split into component pieces -- everything that is non-alphanumeric is * considered a version number separator. */ final String[] stringComponents = versionString.split("[^a-zA-Z0-9]"); //$NON-NLS-1$ final ArrayList versionComponents = new ArrayList(); /* * We trim components to keep only the leading numeric value. */ synchronized (PlatformVersion.class) { if (componentPattern == null) { try { componentPattern = Pattern.compile("^([0-9]+)"); //$NON-NLS-1$ } catch (final Exception e) { logger.error("Could not compile version number regex", e); //$NON-NLS-1$ return new int[0]; } } } for (int i = 0; i < stringComponents.length; i++) { /* * Trim to keep only the leading numeric value. If we're left with * nothing (ie, this component started with a letter), then do not * add it to the version number and stop. */ final Matcher match = componentPattern.matcher(stringComponents[i]); if (match.find()) { try { versionComponents.add(new Integer(stringComponents[i].substring(match.start(), match.end()))); } catch (final Exception e) { logger.warn("Could not coerce version number into format: " + versionString, e); //$NON-NLS-1$ break; } } else { /* Component did not start with a numeric value, stopping. */ break; } } /* Strip trailing zeroes. */ while (versionComponents.size() > 0 && versionComponents.get(versionComponents.size() - 1).equals(INTEGER_ZERO)) { versionComponents.remove(versionComponents.size() - 1); } /* Convert to int array */ final int[] version = new int[versionComponents.size()]; for (int i = 0; i < versionComponents.size(); i++) { version[i] = ((Integer) versionComponents.get(i)).intValue(); } return version; }