Simple function in Java This is a JUnit asserts for this function: 

    assertEquals(0, obj.generateListSize(0));
    assertEquals(1, obj.generateListSize(1));
    assertEquals(1, obj.generateListSize(2));
    assertEquals(3, obj.generateListSize(3));
    assertEquals(3, obj.generateListSize(4));
    assertEquals(5, obj.generateListSize(5));
    assertEquals(5, obj.generateListSize(6));
    assertEquals(7, obj.generateListSize(7));
    assertEquals(7, obj.generateListSize(8));
    assertEquals(7, obj.generateListSize(9));
    assertEquals(10, obj.generateListSize(10));
    assertEquals(10, obj.generateListSize(11));
    assertEquals(10, obj.generateListSize(12));


and this is my implementation:

public int generateListSize(int listSize) {
        int result;
        if (listSize &lt; 1) {
            result = 0;
        } else if (7 &lt; listSize &amp;&amp; listSize &lt; 10) {
            result = 7;
        } else if (10 &lt;= listSize) {
            result = 10;
        } else if (listSize % 2 == 0) {
            result = listSize - 1;
        } else {
            result = listSize;
        }
        return result;
    }


This function is use to truncate list to 1,3,5,7,10 elements. 
When list has 8 elements then return is 7.
I wouldn't search for a "rule", just store the "truncate points"

private final static int[] truncateSizes = {10,7,5,3,1,0};

public int generateListSize(int listSize) {
   for(int truncateSize  : truncateSizes) {
      if (listSize &gt;= truncateSize) { 
        return truncateSize; 
      }
   }
   throw new IllegalArgumentException("Negative list size");
}