code: @SuppressWarnings("unchecked")
      private static List<Object> filterConstantMsgs(List<Object> order, FactorGraph fg) {
          ArrayList<Object> filt = new ArrayList<Object>();
          for (Object item : order) {
              if (item instanceof List) {
                  List<Object> items = filterConstantMsgs((List<Object>) item, fg);
                  if (items.size() > 0) {
                      filt.add(items);
                  }
              } else if (item instanceof Integer) {
                  // If the parent node is not a leaf.
                  if (!isConstantMsg((Integer) item, fg)) {
                      filt.add(item);
                  }
              } else if (item instanceof GlobalFactor) {
                  filt.add(item);
              } else {
                  throw new RuntimeException("Invalid type in order: " + item.getClass());
              }
          }
          return filt;
      }
docs: Filters edges from a leaf node.