Example usage for java.util Collections reverse

List of usage examples for java.util Collections reverse

Introduction

In this page you can find the example usage for java.util Collections reverse.

Prototype

@SuppressWarnings({ "rawtypes", "unchecked" })
public static void reverse(List<?> list) 

Source Link

Document

Reverses the order of the elements in the specified list.

This method runs in linear time.

Usage

From source file:com.omniburst.winetv.android.browser.VideoProvider.java

public static List<MediaInfo> buildMedia(String url) throws JSONException {

    if (null != mediaList) {
        return mediaList;
    }/*from  w w w.  j a v  a2  s.  c  o m*/
    mediaList = new ArrayList<MediaInfo>();
    JSONObject jsonObj = new VideoProvider().parseUrl(url);
    JSONObject wineSpotTVAppData = jsonObj.getJSONObject("WineSpotTVAppData");
    JSONArray episodes = wineSpotTVAppData.getJSONArray("episode");
    if (episodes != null) {
        for (int i = 0; i < episodes.length(); i++) {
            JSONObject episode = episodes.getJSONObject(i);

            String subTitle = episode.getString("episodeDes");
            String videoUrl = episode.getString("videoURL");
            String imageurl = episode.getString("episodeImg");
            String bigImageurl = episode.getString("episodeImg");
            String title = episode.getString("episodeTitle");
            String studio = episode.getString("episodeShow");
            mediaList.add(buildMediaInfo(title, studio, subTitle, videoUrl, imageurl, bigImageurl));
        }
    }

    //        JSONArray categories = jsonObj.getJSONArray(TAG_CATEGORIES);
    //        if (null != categories) {
    //            for (int i = 0; i < categories.length(); i++) {
    //                JSONObject category = categories.getJSONObject(i);
    //                category.getString(TAG_NAME);
    //                JSONArray videos = category.getJSONArray(getJsonMediaTag());
    //                if (null != videos) {
    //                    for (int j = 0; j < videos.length(); j++) {
    //                        JSONObject video = videos.getJSONObject(j);
    //                        String subTitle = video.getString(TAG_SUBTITLE);
    //                        JSONArray videoUrls = video.getJSONArray(TAG_SOURCES);
    //                        if (null == videoUrls || videoUrls.length() == 0) {
    //                            continue;
    //                        }
    //                        String videoUrl = videoUrls.getString(0);
    //                        String imageurl = getThumbPrefix() + video.getString(TAG_THUMB);
    //                        String bigImageurl = getThumbPrefix() + video.getString(TAG_IMG_780_1200);
    //                        String title = video.getString(TAG_TITLE);
    //                        String studio = video.getString(TAG_STUDIO);
    //                        mediaList.add(buildMediaInfo(title, studio, subTitle, videoUrl, imageurl,
    //                                bigImageurl));
    //                    }
    //                }
    //            }
    //        }
    Collections.reverse(mediaList);
    return mediaList;
}

From source file:com.antsdb.saltedfish.nosql.DumpRow.java

private void dump() throws Exception {
    if (this.isVerbose) {
        String str = BytesUtil.toHex(this.key);
        str = StringUtils.replace(str, "\n", "\n     ");
        println("key: %s", str);
    }/*from w  ww .  ja  v  a2s .  co  m*/

    // find tablet files

    this.findTabletFiles(this.home);
    Collections.sort(this.files);
    Collections.reverse(this.files);

    // create mapped buffers

    for (File i : this.files) {
        try (RandomAccessFile raf = new RandomAccessFile(i, "r")) {
            Tablet tablet = new Tablet();
            this.tablets.add(tablet);
            tablet.buf = raf.getChannel().map(MapMode.READ_ONLY, 0, i.length());
            ;
            tablet.file = i;
        }
        if (isVerbose) {
            println("loading file: %s", i);
        }
    }

    // find row

    List<Long> sprows = new ArrayList<>();
    for (Tablet tablet : this.tablets) {
        MappedByteBuffer buf = tablet.buf;
        long addr = UberUtil.getAddress(buf);
        BluntHeap heap = new BluntHeap(addr + MemTablet.HEADER_SIZE, 0);
        heap.position(buf.capacity() - MemTablet.HEADER_SIZE);
        FishSkipList slist = FishSkipList.alloc(heap, new VariableLengthLongComparator());
        long pHead = slist.get(this.pKey);
        if (pHead == 0) {
            continue;
        }
        dumpRowVersions(tablet, heap, pHead, sprows);
    }

    // dump each row

    for (long spRow : sprows) {
        dumpRow(spRow);
    }
}

From source file:com.github.caldav4j.functional.support.CalDavFixture.java

public void tearDown() throws IOException {
    // clean up in reverse order

    Collections.reverse(deleteOnTearDownPaths);

    for (String path : deleteOnTearDownPaths) {
        delete(path);//  w ww .  java2s. c  om
    }
}

From source file:controller.HostelController.java

@ResponseBody
@RequestMapping(value = "/addPlan.do")
public Map addPlan(@RequestBody Plan plan, HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    hostelService.addPlan(plan.getHostelId(), plan.getStartData(), plan.getOverData(), plan.getRoomNum(),
            plan.getPrice());/*from  w  ww. ja va  2  s  .c  om*/
    Map<String, Object> result = new HashMap<String, Object>();
    List<Plan> plans = hostelService.getPlans(plan.getHostelId());
    Collections.reverse(plans);
    result.put("plans", plans);
    return result;
}

From source file:jp.co.tis.gsp.tools.dba.dialect.SqlserverDialect.java

@Override
public void dropAll(String user, String password, String adminUser, String adminPassword, String schema)
        throws MojoExecutionException {
    Connection conn = null;// w w w .  j a  va 2  s  . c  o m
    Statement stmt = null;
    PreparedStatement dropStmt;
    try {
        conn = DriverManager.getConnection(url, adminUser, adminPassword);
        stmt = conn.createStatement();

        // ???????
        if (!existsSchema(conn, schema)) {
            stmt.execute("CREATE SCHEMA " + schema);
            conn.createStatement().execute("ALTER USER " + user + " WITH DEFAULT_SCHEMA = " + schema);

            if (!StringUtils.equalsIgnoreCase(schema, "dbo") && !StringUtils.equalsIgnoreCase(schema, "sys")
                    && !StringUtils.equalsIgnoreCase(schema, "INFORMATION_SCHEMA")) {
                stmt.execute("ALTER AUTHORIZATION ON SCHEMA::" + schema + " TO " + user);
            }

            return;
        } else {
            conn.createStatement().execute("ALTER USER " + user + " WITH DEFAULT_SCHEMA = " + schema);

            if (!StringUtils.equalsIgnoreCase(schema, "dbo") && !StringUtils.equalsIgnoreCase(schema, "sys")
                    && !StringUtils.equalsIgnoreCase(schema, "INFORMATION_SCHEMA")) {
                stmt.execute("ALTER AUTHORIZATION ON SCHEMA::" + schema + " TO " + user);
            }
        }

        // ????
        EntityDependencyParser parser = new EntityDependencyParser();
        parser.parse(conn, url, schema);
        final List<String> tableList = parser.getTableList();
        Collections.reverse(tableList);
        for (String table : tableList) {
            dropObject(conn, schema, "TABLE", table);
        }

        // ??
        dropStmt = conn.prepareStatement("SELECT name, type_desc FROM sys.objects WHERE schema_id = SCHEMA_ID('"
                + schema + "') AND type IN ('U','V')");
        ResultSet rs = dropStmt.executeQuery();
        while (rs.next()) {
            if (!tableList.contains(rs.getString("name"))) {
                String objectType = getObjectType(rs.getString("type_desc"));
                if (objectType != null) {
                    dropObject(conn, schema, objectType, rs.getString("name"));
                }
            }
        }
    } catch (SQLException e) {
        throw new MojoExecutionException("?", e);
    } finally {
        StatementUtil.close(stmt);
        ConnectionUtil.close(conn);
    }
}

From source file:de.voolk.marbles.persistence.services.PageService.java

@Override
public List<IPage> getPagePath(IUser user, IPage page) {
    Page currentPage = resolve(Page.class, page);
    List<IPage> path = new ArrayList<IPage>();
    path.add(currentPage);//from  ww  w  .j  a  va2s. com
    while (!currentPage.isRoot()) {
        currentPage = currentPage.getParent();
        path.add(currentPage);
    }
    Collections.reverse(path);
    return path;
}

From source file:com.hp.alm.ali.idea.entity.tree.EntityNode.java

public String toString() {
    String name = entity.getPropertyValue("name");
    if (loading) {
        name += "..."; // TODO: show as icon
    }//from   w w  w .  j av  a  2  s . c o  m
    String filter = model.getFilter();
    if (!filter.isEmpty()) {
        Matcher matcher = Pattern.compile(wildcardToRegex(filter), Pattern.CASE_INSENSITIVE).matcher(name);
        List<Pair<Integer, Integer>> list = new LinkedList<Pair<Integer, Integer>>();
        while (matcher.find()) {
            list.add(new Pair<Integer, Integer>(matcher.start(), matcher.end()));
        }
        if (!list.isEmpty()) {
            Collections.reverse(list);
            for (Pair<Integer, Integer> match : list) {
                name = name.substring(0, match.first) + "<b>" + name.substring(match.first, match.second)
                        + "</b>" + name.substring(match.second);
            }
            return "<html>" + name + "</html>";
        }
    }
    return name;
}

From source file:org.dhara.portal.web.restAPI.RestExperimentAPI.java

public ArrayList<ExperimentHelper> reverseList(List<ExperimentHelper> list) {

    if (list == null || list.isEmpty()) {
        return null;
    }//from w ww.j  a  v a 2  s .  com

    ArrayList<ExperimentHelper> riversedlist = new ArrayList<ExperimentHelper>(list);

    Collections.reverse(riversedlist);
    return riversedlist;

}

From source file:controller.VisLP.java

/**
 * @param  points/*from w  w  w  .j  ava 2 s  .c  om*/
 *         Unordered list of points that can form a
 *         convex polygon, but in the given order
 *         does not necessarily form a convex
 *         polygon if edges are drawn between the
 *         points in the given order.
 * @return 
 *         An ordered list of points that when edges
 *         are drawn in this order is guaranteed to
 *         form a convex polygon.
 */
static Point2D[] convex(Point2D[] points) {
    /* 
     * Sort the points first on x-value then
     * on y-value, both in ascending order.
     */
    Arrays.sort(points, new Comparator<Point2D>() {
        @Override
        public int compare(Point2D o1, Point2D o2) {
            double s = o1.getX() - o2.getX();
            if (s > 0)
                return 1;
            if (s < 0)
                return -1;

            s = o1.getY() - o2.getY();
            if (s > 0)
                return 1;
            if (s < 0)
                return -1;

            return 0;
        }
    });

    Point2D x_min = points[0];
    Point2D x_max = points[points.length - 1];

    ArrayList<Point2D> upper = new ArrayList<Point2D>();
    ArrayList<Point2D> lower = new ArrayList<Point2D>();

    upper.add(x_min);

    /* Find the slope of the line L connecting x_min and x_max */
    double mx = x_max.getX() - x_min.getX();
    double my = x_max.getY() - x_min.getY();
    double m = my / mx;

    /* Intersection of y-axis */
    double b = x_max.getY() - (m * x_max.getX());

    /* Add points above/below L to upper/lower, respectively */
    for (int i = 1; i < points.length - 1; i++) {
        Point2D p2d = points[i];
        double y = p2d.getX() * m + b;

        if (p2d.getY() >= y)
            upper.add(p2d);
        else
            lower.add(p2d);
    }

    /* Sort the lower list in descending order */
    lower.add(x_max);
    Collections.reverse(lower);

    upper.addAll(lower);
    return upper.toArray(new Point2D[0]);
}

From source file:org.springframework.cloud.config.server.environment.VaultEnvironmentRepository.java

private List<String> findKeys(String application, List<String> profiles) {
    List<String> keys = new ArrayList<>();

    if (StringUtils.hasText(this.defaultKey)) {
        keys.add(this.defaultKey);
        addProfiles(keys, this.defaultKey, profiles);
    }//w w  w.  ja v a  2  s. c  om

    keys.add(application);
    addProfiles(keys, application, profiles);

    Collections.reverse(keys);
    return keys;
}