My apologies. Here's the Java function to implement Gray code and return the next sequence code after a given code in a given direction of rotation:

Java:
import java.util.List;
import java.util.ArrayList;

public class GrayCode {
  
  public static List<Integer> grayCode(int n) {
    List<Integer> result = new ArrayList<>();
    result.add(0);
    for (int i = 0; i < n; i++) {
      int size = result.size();
      for (int j = size - 1; j >= 0; j--) {
        result.add(result.get(j) | 1 << i);
      }
    }
    return result;
  }
  
  public static int nextSequenceCode(int code, int direction, int n) {
    List<Integer> grayCodes = grayCode(n);
    int index = grayCodes.indexOf(code);
    if (direction == 1) {
      if (index == grayCodes.size() - 1) {
        return grayCodes.get(0);
      } else {
        return grayCodes.get(index + 1);
      }
    } else {
      if (index == 0) {
        return grayCodes.get(grayCodes.size() - 1);
      } else {
        return grayCodes.get(index - 1);
      }
    }
  }
}

The grayCode function generates the sequence of Gray codes for a given number of bits n. The nextSequenceCode function returns the next sequence code after a given code code in the specified direction of rotation direction. The direction argument should be 1 for clockwise and -1 for counter-clockwise.
spam fails_task lang_mismatch pii not_appropriate hate_speech sexual_content quality toxicity humor helpfulness creativity violence