public static int computeStoredBoundOnRoleset(NamedDescription relation, Stella_Object instance, Keyword lowerorupper) {
    { Skolem roleset = NamedDescription.getRolesetOf(relation, instance);
      Stella_Object cardinality = null;
      edu.isi.powerloom.pl_kernel_kb.IntervalCache intervalcache = null;
      Stella_Object bound = null;

      if (roleset == null) {
        return (Stella.NULL_INTEGER);
      }
      cardinality = Logic.accessBinaryValue(roleset, Logic.SGT_PL_KERNEL_KB_CARDINALITY);
      if (cardinality != null) {
        { Surrogate testValue000 = Stella_Object.safePrimaryType(cardinality);

          if (Surrogate.subtypeOfIntegerP(testValue000)) {
            { IntegerWrapper cardinality000 = ((IntegerWrapper)(cardinality));

              return (cardinality000.wrapperValue);
            }
          }
          else if (Surrogate.subtypeOfP(testValue000, Logic.SGT_LOGIC_SKOLEM)) {
            { Skolem cardinality000 = ((Skolem)(cardinality));

              { 
                intervalcache = edu.isi.powerloom.pl_kernel_kb.PlKernelKb.getIntervalCache(cardinality000);
                if (intervalcache != null) {
                  if (lowerorupper == Logic.KWD_LOWER) {
                    bound = intervalcache.lowerBound;
                  }
                  else if (lowerorupper == Logic.KWD_UPPER) {
                    bound = intervalcache.upperBound;
                  }
                  else {
                    { OutputStringStream stream000 = OutputStringStream.newOutputStringStream();

                      stream000.nativeStream.print("`" + lowerorupper + "' is not a valid case option");
                      throw ((StellaException)(StellaException.newStellaException(stream000.theStringReader()).fillInStackTrace()));
                    }
                  }
                  if ((bound != null) &&
                      Stella_Object.isaP(bound, Logic.SGT_STELLA_INTEGER_WRAPPER)) {
                    return (IntegerWrapper.unwrapInteger(((IntegerWrapper)(bound))));
                  }
                }
              }
            }
          }
          else {
            { OutputStringStream stream001 = OutputStringStream.newOutputStringStream();

              stream001.nativeStream.print("`" + testValue000 + "' is not a valid case option");
              throw ((StellaException)(StellaException.newStellaException(stream001.theStringReader()).fillInStackTrace()));
            }
          }
        }
      }
      return (Stella.NULL_INTEGER);
    }
  }