List of usage examples for java.util Vector addElement
public synchronized void addElement(E obj)
From source file:edu.ku.brc.ui.UIHelper.java
/** * Helper method for returning data if it is of a particular Class. * Meaning is this data implementing an interface or is it derived from some other class. * @param data the generic data// www . j a v a 2 s . c o m * @param classObj the class in questions * @return the data if it is derived from or implements, can it be cast to */ public static Object getDataForClass(final Object data, Class<?> classObj) { // Short circut if all they are interested in is the generic "Object" if (classObj == Object.class) { return data; } // Check to see if it supports the aggrgation interface if (data instanceof GhostDataAggregatable) { Object newData = ((GhostDataAggregatable) data).getDataForClass(classObj); if (newData != null) { return newData; } } Vector<Class<?>> classes = new Vector<Class<?>>(); // First Check interfaces Class<?>[] theInterfaces = data.getClass().getInterfaces(); for (Class<?> co : theInterfaces) { classes.add(co); } if (classes.contains(classObj)) { return data; } classes.clear(); // Now Check super classes Class<?> superclass = data.getClass().getSuperclass(); while (superclass != null) { classes.addElement(superclass); superclass = superclass.getSuperclass(); } // Wow, it doesn't support anything return null; }
From source file:edu.umn.cs.spatialHadoop.mapreduce.SpatialInputFormat3.java
@Override public List<InputSplit> getSplits(JobContext job) throws IOException { List<InputSplit> splits = super.getSplits(job); Configuration jobConf = job.getConfiguration(); if (jobConf.getInt(CombineSplits, 1) > 1) { long t1 = System.currentTimeMillis(); int combine = jobConf.getInt(CombineSplits, 1); /*/*from w ww . j av a 2 s .c o m*/ * Combine splits to reduce number of map tasks. Currently, this is done * using a greedy algorithm that combines splits based on how many hosts * they share. * TODO: Use a graph clustering algorithm where each vertex represents a * split, and each edge is weighted with number of shared hosts between * the two splits */ Vector<Vector<FileSplit>> openSplits = new Vector<Vector<FileSplit>>(); int maxNumberOfSplits = (int) Math.ceil((float) splits.size() / combine); List<InputSplit> combinedSplits = new Vector<InputSplit>(); for (InputSplit split : splits) { FileSplit fsplit = (FileSplit) split; int maxSimilarity = -1; // Best similarity found so far int bestFit = -1; // Index of a random open split with max similarity int numMatches = 0; // Number of splits with max similarity for (int i = 0; i < openSplits.size(); i++) { Vector<FileSplit> splitList = openSplits.elementAt(i); int similarity = 0; for (FileSplit otherSplit : splitList) { for (String host1 : fsplit.getLocations()) for (String host2 : otherSplit.getLocations()) if (host1.equals(host2)) similarity++; } if (similarity > maxSimilarity) { maxSimilarity = similarity; bestFit = i; numMatches = 1; } else if (similarity == maxSimilarity) { numMatches++; // Replace with a probability () for a reservoir sample double random = Math.random(); if (random < (double) 1 / numMatches) { // Replace the element in the reservoir bestFit = i; } } } if (maxSimilarity > 0 || (openSplits.size() + combinedSplits.size()) >= maxNumberOfSplits) { // Good fit || cannot create more open splits, // add it to an existing open split. Vector<FileSplit> bestList = openSplits.elementAt(bestFit); bestList.add(fsplit); if (bestList.size() > combine) { // Reached threshold for this list. Add it to combined splits combinedSplits.add(FileSplitUtil.combineFileSplits(bestList, 0, bestList.size())); // Remove it from open splits openSplits.remove(bestFit); } } else { // Bad fit && can add a new split // Create a new open split just for this one Vector<FileSplit> newOpenSplit = new Vector<FileSplit>(); newOpenSplit.add(fsplit); openSplits.addElement(newOpenSplit); } } // Add all remaining open splits to the list of combined splits for (Vector<FileSplit> openSplit : openSplits) { combinedSplits.add(FileSplitUtil.combineFileSplits(openSplit, 0, openSplit.size())); } String msg = String.format("Combined %d splits into %d combined splits", splits.size(), combinedSplits.size()); splits.clear(); splits.addAll(combinedSplits); long t2 = System.currentTimeMillis(); LOG.info(msg + " in " + ((t2 - t1) / 1000.0) + " seconds"); } return splits; }
From source file:net.rim.ejde.internal.packaging.PackagingManager.java
private Vector<String> getCompileOptions() { Vector<String> options = new Vector<String>(); BlackBerryProperties properties = _bbProject.getProperties(); // TODO java home // get options from the compile section if (properties._compile.getCompressResources().booleanValue()) { options.add(COMPRESS_RESOURCE_OPTION); }/*from w w w . j av a2s . co m*/ if (properties._compile.getConvertImages().booleanValue()) { options.add(CONVERT_PNG_RAPC_OPTION); } if (!properties._compile.getCreateWarningForNoExportedRoutine().booleanValue() || !properties._application.getType().equals(BlackBerryProject.CLDC_APPLICATION)) { options.add(Project.NO_MAIN_RAPC_OPTION); } if (!properties._compile.getOutputCompilerMessages().booleanValue()) { options.add(Project.QUIET_RAPC_OPTION); } if (!StringUtils.isBlank(properties._compile.getAliasList()) && properties._application.getType().equals(BlackBerryProject.LIBRARY)) { options.add(Project.ALIAS_RAPC_OPTION + properties._compile.getAliasList()); } // add other options InternalPackagingUtils.addOtherOptions(options, properties); // add codename int projectType = getProjectTypeID(properties._application.getType()); String outputFileName = PackagingUtils.getRelativeStandardOutputFilePath(_bbProject).toOSString(); if (projectType == Project.LIBRARY) { options.addElement("library=" + outputFileName); } else { options.addElement("codename=" + outputFileName); } if (projectType == Project.MIDLET) { options.addElement("-midlet"); } return options; }
From source file:de.juwimm.cms.remote.ViewServiceSpringImpl.java
/** * @see de.juwimm.cms.remote.ViewServiceSpring#getViewDocuments4Site(java.lang.Integer) *//*from w w w . j a v a2s .c o m*/ @Override protected ViewDocumentValue[] handleGetViewDocuments4Site(Integer siteId) throws Exception { try { Vector<ViewDocumentValue> vec = new Vector<ViewDocumentValue>(); Iterator it = super.getViewDocumentHbmDao().findAll(siteId).iterator(); while (it.hasNext()) { vec.addElement(((ViewDocumentHbm) it.next()).getDao()); } return vec.toArray(new ViewDocumentValue[0]); } catch (Exception e) { throw new UserException(e.getMessage()); } }
From source file:de.juwimm.cms.remote.ViewServiceSpringImpl.java
/** * Get parents to a viewComponent unit, excluding the viewCcomponent, which has a unit. * // ww w .ja va 2 s.c o m * @param viewComponent * @return String with path to this viewComponent */ private String getParents4View(ViewComponentHbm viewComponent) { try { if (viewComponent.getParent().isRoot()) { return "\\"; } } catch (Exception ex) { return "\\"; } Vector<ViewComponentHbm> vec = new Vector<ViewComponentHbm>(); ViewComponentHbm parentView = viewComponent.getParent(); while (parentView.getAssignedUnit() == null) { vec.addElement(parentView); parentView = parentView.getParent(); try { if (parentView.isRoot()) { break; } } catch (Exception ex) { break; } } if (parentView.getAssignedUnit() != null) { vec.addElement(parentView); } StringBuffer sb = new StringBuffer("\\"); for (int i = vec.size() - 1; i > -1; i--) { sb.append((vec.elementAt(i)).getUrlLinkName()); if (i != 0) { sb.append("\\"); } } sb.append("\\").append(viewComponent.getUrlLinkName()); return sb.toString(); }
From source file:de.juwimm.cms.remote.ViewServiceSpringImpl.java
/** * @see de.juwimm.cms.remote.ViewServiceSpring#getParents4ViewComponent(java.lang.Integer) *///from www .j a v a 2 s. co m @Override protected Integer[] handleGetParents4ViewComponent(Integer viewComponentId) throws Exception { try { ViewComponentHbm view = super.getViewComponentHbmDao().load(viewComponentId); Vector<Integer> vec = new Vector<Integer>(); Vector<Integer> topDown = new Vector<Integer>(); ViewComponentHbm parentView = view; while ((parentView = parentView.getParent()) != null) { vec.addElement(parentView.getViewComponentId()); } for (int i = vec.size() - 1; i > -1; i--) { topDown.addElement(vec.elementAt(i)); } return topDown.toArray(new Integer[0]); } catch (Exception e) { throw new UserException(e.getMessage()); } }
From source file:de.juwimm.cms.remote.ViewServiceSpringImpl.java
/** * @see de.juwimm.cms.remote.ViewServiceSpring#getViewComponentChildren(java.lang.Integer) *//*from www. j av a 2 s . com*/ @Override protected ViewComponentValue[] handleGetViewComponentChildren(Integer parentId) throws Exception { try { if (log.isDebugEnabled()) log.debug("begin getViewComponentChildren"); ViewComponentHbm view = super.getViewComponentHbmDao().load(parentId); if (view.isLeaf()) { throw new UserException("node is a leaf."); } Vector<ViewComponentValue> vec = new Vector<ViewComponentValue>(); for (Iterator i = view.getChildren().iterator(); i.hasNext();) { ViewComponentHbm vcHbm = (ViewComponentHbm) i.next(); ViewComponentValue vc = vcHbm.getDao(-1); vec.addElement(vc); } if (log.isDebugEnabled()) log.debug("end getViewComponentChildren"); return vec.toArray(new ViewComponentValue[0]); } catch (Exception e) { throw new UserException(e.getMessage()); } }
From source file:com.dragonflow.StandardMonitor.URLOriginalMonitor.java
public Vector getScalarValues(ScalarProperty scalarproperty, HTTPRequest httprequest, CGI cgi) throws SiteViewException { if (scalarproperty == pCheckContent) { Vector vector = new Vector(); vector.addElement(""); vector.addElement("no content checking"); vector.addElement("on"); vector.addElement("compare to last contents "); vector.addElement("baseline"); vector.addElement("compare to saved contents"); vector.addElement("reset"); vector.addElement("reset saved contents"); return vector; } else {//from ww w . j av a 2 s . c om return super.getScalarValues(scalarproperty, httprequest, cgi); } }
From source file:com.duroty.application.mail.manager.MailManager.java
/** * DOCUMENT ME!//from w w w . j a va 2 s . c o m * * @param hsession DOCUMENT ME! * @param repositoryName DOCUMENT ME! * @param folderName DOCUMENT ME! * @param page DOCUMENT ME! * @param messagesByPage DOCUMENT ME! * @param order DOCUMENT ME! * @param orderType DOCUMENT ME! * * @return DOCUMENT ME! * * @throws MailException DOCUMENT ME! */ public MessageObj getMessage(Session hsession, String repositoryName, String mid, boolean readReferences, boolean isHtml, boolean displayImages) throws MailException { ByteArrayOutputStream baos = null; try { Users user = getUser(hsession, repositoryName); Locale locale = new Locale(user.getUseLanguage()); TimeZone timeZone = TimeZone.getDefault(); Date now = new Date(); Calendar calendar = Calendar.getInstance(timeZone, locale); calendar.setTime(now); SimpleDateFormat formatter1 = new SimpleDateFormat("MMM dd", locale); SimpleDateFormat formatter2 = new SimpleDateFormat("HH:mm:ss", locale); SimpleDateFormat formatter3 = new SimpleDateFormat("MM/yy", locale); Criteria crit = hsession.createCriteria(Message.class); crit.add(Restrictions.eq("mesName", mid)); crit.add(Restrictions.eq("users", user)); Message message = (Message) crit.uniqueResult(); message.setMesRecent(false); hsession.update(message); hsession.flush(); MessageObj obj = new MessageObj(message.getMesName()); obj.setBox(message.getMesBox()); obj.setFrom(message.getMesFrom()); obj.setTo(message.getMesTo()); obj.setReplyTo(message.getMesReplyTo()); obj.setCc(message.getMesCc()); if ((message.getAttachments() != null) && (message.getAttachments().size() > 0)) { obj.setHasAttachment(true); Set set = message.getAttachments(); Iterator it = set.iterator(); Vector attachments = new Vector(); while (it.hasNext()) { Attachment attachment = (Attachment) it.next(); AttachmentObj attachmentObj = new AttachmentObj(); attachmentObj.setIdint(attachment.getAttPart()); attachmentObj.setName(attachment.getAttName()); int size = attachment.getAttSize(); size /= 1024; if (size > 1024) { size /= 1024; attachmentObj.setSize(size + " MB"); } else { attachmentObj.setSize(((size > 0) ? (size + "") : "<1") + " kB"); } String extension = (String) this.extensions.get(attachment.getAttContentType()); if (StringUtils.isBlank(extension)) { extension = "generic"; } attachmentObj.setExtension(extension); attachmentObj.setContentType(attachment.getAttContentType()); attachments.addElement(attachmentObj); obj.setAttachments(attachments); } } else { obj.setHasAttachment(false); } int size = message.getMesSize(); size /= 1024; if (size > 1024) { size /= 1024; obj.setSize(size + " MB"); } else { obj.setSize(((size > 0) ? (size + "") : "<1") + " kB"); } if (message.getMesBox().equals(folderSent)) { try { obj.setEmail(message.getMesTo()); } catch (Exception e) { obj.setEmail("unknown to"); } } else { obj.setEmail(message.getMesFrom()); } Date date = message.getMesDate(); if (date != null) { Calendar calendar2 = Calendar.getInstance(timeZone, locale); calendar2.setTime(date); if ((calendar.get(Calendar.YEAR) == calendar2.get(Calendar.YEAR)) && (calendar.get(Calendar.MONTH) == calendar2.get(Calendar.MONTH)) && (calendar.get(Calendar.DATE) == calendar2.get(Calendar.DATE))) { obj.setDateStr(formatter2.format(calendar2.getTime())); } else if (calendar.get(Calendar.YEAR) == calendar2.get(Calendar.YEAR)) { obj.setDateStr(formatter1.format(calendar2.getTime())); } else { obj.setDateStr(formatter3.format(calendar2.getTime())); } } obj.setDate(date); if (message.getLabMeses() != null) { Iterator it = message.getLabMeses().iterator(); StringBuffer label = new StringBuffer(); while (it.hasNext()) { if (label.length() > 0) { label.append(", "); } LabMes labMes = (LabMes) it.next(); label.append(labMes.getId().getLabel().getLabName()); } obj.setLabel(label.toString()); } try { if (StringUtils.isBlank(message.getMesSubject())) { obj.setSubject("(no subject)"); } else { obj.setSubject(message.getMesSubject()); } } catch (Exception ex) { obj.setSubject("(no subject)"); } if (message.isMesFlagged()) { obj.setFlagged(true); } else { obj.setFlagged(false); } if (message.isMesRecent()) { obj.setRecent(true); } else { obj.setRecent(false); } String priority = "normal"; if (MessageUtilities.isHighPriority(message.getMesHeaders())) { priority = "high"; } else if (MessageUtilities.isLowPriority(message.getMesHeaders())) { priority = "low"; } obj.setPriority(priority); String body = message.getMesBody(); if (!StringUtils.isBlank(body)) { obj.setBody(bodyCleaner(body, displayImages)); } else { obj.setBody(""); } String midReferences = message.getMesReferences(); if (readReferences && (midReferences != null) && !midReferences.trim().equals("")) { obj.setReferencesBefore( readReference(hsession, user, mid, midReferences, date, true, isHtml, displayImages)); obj.setReferencesAfter( readReference(hsession, user, mid, midReferences, date, false, isHtml, displayImages)); } return obj; } catch (Exception e) { throw new MailException(e); } finally { IOUtils.closeQuietly(baos); GeneralOperations.closeHibernateSession(hsession); } }
From source file:focusedCrawler.util.parser.PaginaURL.java
/** * Este metodo adiciona um termo na lista de termos com suas posicoes * e' dado tambem uma posicao do termo.//from ww w .j av a2 s . c om * E' usado quando a pagina e' construida */ protected void adicionaTermoPosicaoSemStopList(String termo, int pos) { if (noindex) { return; } if (palavra_posicoes == null) { palavra_posicoes = new Hashtable(); } termo = termo.toLowerCase(); Vector posicoes = (Vector) palavra_posicoes.get(termo); if (posicoes == null) { posicoes = new Vector(); palavra_posicoes.put(termo, posicoes); posicoes.addElement(new Integer(pos)); } else { posicoes.addElement(new Integer(pos)); } }