List of usage examples for java.util Vector get
public synchronized E get(int index)
From source file:Main.java
public int compare(Object a, Object b) { Vector v1 = (Vector) a; Vector v2 = (Vector) b; Object o1 = v1.get(colIndex); Object o2 = v2.get(colIndex); if (o1 instanceof String && ((String) o1).length() == 0) { o1 = null;/*from w w w .ja v a2 s . c om*/ } if (o2 instanceof String && ((String) o2).length() == 0) { o2 = null; } if (o1 == null && o2 == null) { return 0; } else if (o1 == null) { return 1; } else if (o2 == null) { return -1; } else if (o1 instanceof Comparable) { return ((Comparable) o1).compareTo(o2); } else { return o1.toString().compareTo(o2.toString()); } }
From source file:de.mpg.escidoc.services.common.util.Util.java
/** * Eliminates duplicates in a Vector./*from w w w.j av a2 s. c om*/ * @param dirtyVector as Format Vector * @return Vector with unique entries */ public static Vector<Format> getRidOfDuplicatesInVector(Vector<Format> dirtyVector) { Vector<Format> cleanVector = new Vector<Format>(); Format format1; Format format2; for (int i = 0; i < dirtyVector.size(); i++) { boolean duplicate = false; format1 = (Format) dirtyVector.get(i); for (int x = i + 1; x < dirtyVector.size(); x++) { format2 = (Format) dirtyVector.get(x); if (isFormatEqual(format1, format2)) { duplicate = true; } } if (!duplicate) { cleanVector.add(format1); } } return cleanVector; }
From source file:edu.umn.cs.spatialHadoop.nasa.SpatioAggregateQueries.java
/** * Return all matching partitions according to a time range * @param inFile /*ww w. java2 s . c o m*/ * @param params * @return * @throws ParseException * @throws IOException */ private static Vector<Path> selectTemporalPartitions(Path inFile, OperationsParams params) throws ParseException, IOException { // 1- Run a temporal filter step to find all matching temporal partitions Vector<Path> matchingPartitions = new Vector<Path>(); // List of time ranges to check. Initially it contains one range as // specified by the user. Eventually, it can be split into at most two // partitions if partially matched by a partition. Vector<TimeRange> temporalRanges = new Vector<TimeRange>(); System.out.println(new TimeRange(params.get("time"))); temporalRanges.add(new TimeRange(params.get("time"))); Path[] temporalIndexes = new Path[] { new Path(inFile, "yearly"), new Path(inFile, "monthly"), new Path(inFile, "daily") }; int index = 0; final FileSystem fs = inFile.getFileSystem(params); while (index < temporalIndexes.length && !temporalRanges.isEmpty()) { Path indexDir = temporalIndexes[index]; LOG.info("Checking index dir " + indexDir); TemporalIndex temporalIndex = new TemporalIndex(fs, indexDir); for (int iRange = 0; iRange < temporalRanges.size(); iRange++) { TimeRange range = temporalRanges.get(iRange); TemporalPartition[] matches = temporalIndex.selectContained(range.start, range.end); if (matches != null) { LOG.info("Matched " + matches.length + " partitions in " + indexDir); for (TemporalPartition match : matches) { matchingPartitions.add(new Path(indexDir, match.dirName)); } // Update range to remove matching part TemporalPartition firstMatch = matches[0]; TemporalPartition lastMatch = matches[matches.length - 1]; if (range.start < firstMatch.start && range.end > lastMatch.end) { // Need to split the range into two temporalRanges.setElementAt(new TimeRange(range.start, firstMatch.start), iRange); temporalRanges.insertElementAt(new TimeRange(lastMatch.end, range.end), iRange); } else if (range.start < firstMatch.start) { // Update range in-place range.end = firstMatch.start; } else if (range.end > lastMatch.end) { // Update range in-place range.start = lastMatch.end; } else { // Current range was completely covered. Remove it temporalRanges.remove(iRange); } } } index++; } numOfTemporalPartitionsInLastQuery = matchingPartitions.size(); return matchingPartitions; }
From source file:de.mpg.mpdl.inge.transformation.Util.java
/** * Merges a Vector of Format[] into Format[]. * /*w w w.j a va2 s . c om*/ * @param allFormatsV as Format[] Vector * @return Format[] */ public static Format[] mergeFormats(Vector<Format[]> allFormatsV) { Vector<Format> tmpV = new Vector<Format>(); Format[] tmpA; for (int i = 0; i < allFormatsV.size(); i++) { tmpA = allFormatsV.get(i); if (tmpA != null) { for (int x = 0; x < tmpA.length; x++) { tmpV.add(tmpA[x]); // System.out.println(tmpA[x].getName()); } } } tmpV = getRidOfDuplicatesInVector(tmpV); return formatVectorToFormatArray(tmpV); }
From source file:edu.stanford.cfuller.imageanalysistools.clustering.ObjectClustering.java
/** * Sets up a set of ClusterObjects and a set of Clusters from two Image masks, one labeled with individual objects, and one labeled with all objects in a single cluster grouped with a single label. * * @param labeledByObject An Image mask with all objects in the Image labeled with an unique greylevel value. These labels must start with 1 and be consecutive. * @param labeledByCluster An Image mask with all the objects in each cluster labeled with the same unique greylevel value. These labels must start with 1 and be consecutive. * @param clusterObjects A Vector of ClusterObjects that will contain the initialized ClusterObjects on return; this can be empty, and any contents will be erased. * @param clusters A Vector of Clusters that will contain the initialized Clusters on return; this can be empty, and any contents will be erased. * @param k The number of clusters in the Image. This must be the same as the number of unique nonzero greylevels in the labeledByCluster Image. * @return The number of ClusterObjects in the Image. *///from w ww.j av a 2s . c o m public static int initializeObjectsAndClustersFromClusterImage(Image labeledByObject, Image labeledByCluster, Vector<ClusterObject> clusterObjects, Vector<Cluster> clusters, int k) { clusters.clear(); for (int j = 0; j < k; j++) { clusters.add(new Cluster()); clusters.get(j).setID(j + 1); } Histogram h = new Histogram(labeledByObject); int n = h.getMaxValue(); clusterObjects.clear(); for (int j = 0; j < n; j++) { clusterObjects.add(new ClusterObject()); clusterObjects.get(j).setCentroidComponents(0, 0, 0); clusterObjects.get(j).setnPixels(0); } for (ImageCoordinate i : labeledByObject) { if (labeledByObject.getValue(i) > 0) { int value = (int) (labeledByObject.getValue(i)); clusterObjects.get(value - 1).incrementnPixels(); clusterObjects.get(value - 1).setCentroid( clusterObjects.get(value - 1).getCentroid().add(new Vector3D(i.get(ImageCoordinate.X), i.get(ImageCoordinate.Y), i.get(ImageCoordinate.Z)))); } } for (int j = 0; j < n; j++) { ClusterObject current = clusterObjects.get(j); current.setCentroid(current.getCentroid().scalarMultiply(1.0 / current.getnPixels())); } for (ImageCoordinate i : labeledByObject) { int clusterValue = (int) labeledByCluster.getValue(i); int objectValue = (int) labeledByObject.getValue(i); if (clusterValue == 0 || objectValue == 0) { continue; } clusters.get(clusterValue - 1).getObjectSet().add(clusterObjects.get(objectValue - 1)); } for (Cluster c : clusters) { int objectCounter = 0; c.setCentroidComponents(0, 0, 0); for (ClusterObject co : c.getObjectSet()) { objectCounter++; co.setCurrentCluster(c); c.setCentroid(c.getCentroid().add(co.getCentroid())); } c.setCentroid(c.getCentroid().scalarMultiply(1.0 / objectCounter)); } return n; }
From source file:marytts.util.io.FileUtils.java
public static void writeTextFile(Vector<String> textInRows, String textFile) { PrintWriter out = null;/*from w w w .jav a 2 s . c om*/ try { out = new PrintWriter(new FileWriter(textFile)); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (out != null) { for (int i = 0; i < textInRows.size(); i++) out.println(textInRows.get(i)); out.close(); } else System.out.println("Error! Cannot create file: " + textFile); }
From source file:com.globalsight.everest.webapp.pagehandler.administration.vendors.VendorHelper.java
/** * Save the request parameters from the edit role page *///from ww w. j a v a2 s.c o m public static void modifyRole(Vendor vendor, HttpServletRequest request, SessionManager sessionMgr, Locale uiLocale) throws EnvoyServletException { LocalePair lp = (LocalePair) sessionMgr.getAttribute("localePair"); GlobalSightLocale srcLocale = (GlobalSightLocale) sessionMgr.getAttribute("sourceLocale"); GlobalSightLocale targLocale = (GlobalSightLocale) sessionMgr.getAttribute("targetLocale"); // Get all possible activities Vector activities = UserHandlerHelper.getAllActivities(uiLocale); for (int i = 0; i < activities.size(); i++) { Activity activity = (Activity) activities.get(i); String activityName = (String) request.getParameter(activity.getActivityName()); if (activityName != null) { Rate rate = getRate(activity, request); VendorRole role = activityInRole(activity.getName(), lp, vendor); if (role != null) { // update the role role.setRate(rate); } else { // add new role VendorRole newRole = new VendorRole(activity, lp, rate); vendor.addRole(newRole); } } else { VendorRole role = activityInRole(activity.getName(), lp, vendor); if (role != null) { // remove role vendor.removeRole(role); } } } }
From source file:com.globalsight.everest.webapp.pagehandler.administration.vendors.VendorHelper.java
/** * Return a hashtable where the key is an activity and the value is a list * of the activity rates//from w w w . ja v a 2s . c o m */ public static HashMap getActivities(GlobalSightLocale sourceLocale, GlobalSightLocale targetLocale, Locale uiLocale) throws EnvoyServletException { boolean isCostingEnabled = false; try { SystemConfiguration sc = SystemConfiguration.getInstance(); isCostingEnabled = sc.getBooleanParameter(SystemConfigParamNames.COSTING_ENABLED); } catch (Exception e) { } try { HashMap activityHash = new HashMap(); Vector activities = UserHandlerHelper.getAllActivities(uiLocale); for (int i = 0; i < activities.size(); i++) { Activity activity = (Activity) activities.get(i); Collection activityRates = null; if (isCostingEnabled) { activityRates = ServerProxy.getCostingEngine().getRates(activity, sourceLocale, targetLocale); } activityHash.put(activity, activityRates); } return activityHash; } catch (Exception e) { throw new EnvoyServletException(e); } }
From source file:com.globalsight.everest.webapp.pagehandler.administration.vendors.VendorHelper.java
/** * Save the request parameters from the new role page *//* w ww . j a v a 2s . c o m*/ public static void newRole(Vendor vendor, HttpServletRequest request, SessionManager sessionMgr, Locale uiLocale) throws EnvoyServletException { // Get the source and target locales String src = request.getParameter("srcLocales"); String targ = request.getParameter("targLocales"); if (src.equals("-1") || targ.equals("-1")) { // the user isn't adding a role (it's not required) return; } LocalePair lp = null; try { GlobalSightLocale sourceLocale = ServerProxy.getLocaleManager().getLocaleById(Long.parseLong(src)); GlobalSightLocale targetLocale = ServerProxy.getLocaleManager().getLocaleById(Long.parseLong(targ)); lp = ServerProxy.getLocaleManager().getLocalePairBySourceTargetIds(sourceLocale.getId(), targetLocale.getId()); } catch (Exception e) { throw new EnvoyServletException(e); } // Get all activities and loop thru to get set ones Vector activities = UserHandlerHelper.getAllActivities(uiLocale); for (int i = 0; i < activities.size(); i++) { Activity activity = (Activity) activities.get(i); String activityName = (String) request.getParameter(activity.getActivityName()); Rate rate = null; if (activityName != null) { rate = getRate(activity, request); VendorRole newRole = new VendorRole(activity, lp, rate); vendor.addRole(newRole); } } }
From source file:edu.stanford.cfuller.imageanalysistools.clustering.ObjectClustering.java
/** * Relabels an Image mask that is labeled with an individual greylevel for each cluster object to have all objects in a single cluster labeled with the same value. * * //from w w w. ja v a 2 s. c o m * @param output The Image mask labeled with unique greylevels for each cluster object; this should have regions labeled according to the same scheme used to generate the clusters and objects. It will be overwritten. * @param clusterObjects A Vector containing the ClusterObjects corresponding to the labeled objects in the Image mask. * @param clusters A Vector containing the Clusters comprised of the ClusterObjects that will determine the labels in the output Image. * @param k The number of Clusters. */ public static void clustersToMask(WritableImage output, Vector<ClusterObject> clusterObjects, Vector<Cluster> clusters, int k) { for (ImageCoordinate i : output) { int value = (int) output.getValue(i); if (value > 0) { output.setValue(i, clusterObjects.get(value - 1).getCurrentCluster().getID()); } } }