code: public synchronized static boolean areConnectedUpstream(PfafstetterNumber p1,
                                                              PfafstetterNumber p2) {
  
          List<Integer> p1OrdersList = p1.getOrdersList();
          List<Integer> p2OrdersList = p2.getOrdersList();
  
          int levelDiff = p1OrdersList.size() - p2OrdersList.size();
          if (levelDiff == 0) {
              if (p1.toStringUpToLastLevel().equals(p2.toStringUpToLastLevel())) {
                  int p1Last = p1OrdersList.get(p1OrdersList.size() - 1);
                  int p2Last = p2OrdersList.get(p2OrdersList.size() - 1);
                  if (p2Last == p1Last + 1 || p2Last == p1Last + 2) {
                      return p1Last % 2 != 0;
                  }
              }
          } else if (levelDiff == -1) {
              if (p2.toString().startsWith(p1.toStringUpToLastLevel())) {
                  int p2Last = p2OrdersList.get(p2OrdersList.size() - 1);
                  if (p2Last != 1) {
                      return false;
                  }
                  int p1Last = p1OrdersList.get(p1OrdersList.size() - 1);
                  int p2LastMinus1 = p2OrdersList.get(p2OrdersList.size() - 2);
                  if (p2LastMinus1 == p1Last + 1 || p2Last == p1Last + 2) {
                      return p1Last % 2 != 0;
                  }
              }
          }
          return false;
      }
docs: Checks if two pfafstetter are connected upstream, i.e. p1 is more downstream than p2
  
  @param p1 the first pfafstetter.
  @param p2 the second pfafstetter.
  @return <code>true</code> if the first is more upstream than the second.