// Path: app/src/main/java/com/hippo/nimingban/client/data/Forum.java
// public abstract class Forum {
// 
//     public abstract Site getNMBSite();
// 
//     public abstract String getNMBId();
// 
//     public abstract CharSequence getNMBDisplayname();
// 
//     public abstract String getNMBMsg();
// }


import com.hippo.nimingban.client.data.Forum;
import com.hippo.nimingban.dao.ACForumRaw;
import de.greenrobot.dao.query.LazyList;
package com.hippo.nimingban.util;



public class ForumAutoSortingUtils {

    private static final int FREQUENCY_UPPER_BOUND = 1 << 15;

    private static Integer setPinned(Integer freq) {
        return freq | FREQUENCY_UPPER_BOUND;
    }

    private static Integer setUnpinned(Integer freq) {
        return freq & (FREQUENCY_UPPER_BOUND - 1);
    }

    private static boolean isPinned(Integer freq) {
        return (freq & FREQUENCY_UPPER_BOUND) != 0;
    }

    private static Integer incrementFrequency(Integer freq) {
        if (freq == null) {
            return 1;
        }
        boolean pinned = isPinned(freq);
        int result = pinned ? setUnpinned(freq) : freq;

// Path: app/src/main/java/com/hippo/nimingban/client/data/Forum.java
// public abstract class Forum {
// 
//     public abstract Site getNMBSite();
// 
//     public abstract String getNMBId();
// 
//     public abstract CharSequence getNMBDisplayname();
// 
//     public abstract String getNMBMsg();
// }


// Path: app/src/main/java/com/hippo/nimingban/util/ForumAutoSortingUtils.java
import com.hippo.nimingban.client.data.Forum;
import com.hippo.nimingban.dao.ACForumRaw;
import de.greenrobot.dao.query.LazyList;

package com.hippo.nimingban.util;



public class ForumAutoSortingUtils {

    private static final int FREQUENCY_UPPER_BOUND = 1 << 15;

    private static Integer setPinned(Integer freq) {
        return freq | FREQUENCY_UPPER_BOUND;
    }

    private static Integer setUnpinned(Integer freq) {
        return freq & (FREQUENCY_UPPER_BOUND - 1);
    }

    private static boolean isPinned(Integer freq) {
        return (freq & FREQUENCY_UPPER_BOUND) != 0;
    }

    private static Integer incrementFrequency(Integer freq) {
        if (freq == null) {
            return 1;
        }
        boolean pinned = isPinned(freq);
        int result = pinned ? setUnpinned(freq) : freq;

        if (result + 1 < FREQUENCY_UPPER_BOUND) { // make sure freq be in bound