// Path: gnikrap-core/src/main/java/org/gnikrap/utils/MapBuilder.java
// public final class MapBuilder<K, V> {
//   private final Map<K, V> map;
// 
//   public MapBuilder(Map<K, V> map) {
//     this.map = map;
//   }
// 
//   public MapBuilder<K, V> put(K k, V v) {
//     map.put(k, v);
//     return this;
//   }
// 
//   public Map<K, V> build() {
//     return map;
//   }
// 
//   public static final <K, V> MapBuilder<K, V> buildHashMap(K k, V v) {
//     return new MapBuilder<K, V>(new HashMap<K, V>()).put(k, v);
//   }
// 
//   public static final <K, V> MapBuilder<K, V> buildTreeMapBuilder() {
//     return new MapBuilder<K, V>(new TreeMap<K, V>());
//   }
// }


import lejos.hardware.port.Port;
import lejos.hardware.sensor.EV3IRSensor;
import lejos.hardware.sensor.SensorMode;
import org.gnikrap.utils.MapBuilder;
import org.gnikrap.utils.ScriptApi;
  @ScriptApi
  public void setChannel(int channel) throws EV3ScriptException {
    checkChannel(channel);
    this.channel = channel;
  }

  @ScriptApi
  public RemoteCommandResult getRemoteCommand() {
    int temp = delegate.getRemoteCommand(channel - 1); // channel 0-based
    logger.log(EV3Constants.IR_SENSOR_REMOTE, temp);
    return new RemoteCommandResult(temp);
  }

  @ScriptApi
  public float getDistance() {
    distanceMode.fetchSample(distanceSample, 0);
    float result = distanceSample[0];
    logger.log(EV3Constants.IR_SENSOR_DISTANCE, result);
    return result;
  }

  @ScriptApi
  public SeekBeaconResult seekBeacon() {
    seekMode.fetchSample(seekSample, 0);
    // TODO: Something to log ?!
    return new SeekBeaconResult(seekSample, channel);
  }

  protected static void checkChannel(int channel) throws EV3ScriptException {
    if (channel < 1 || channel > 4) {
// Path: gnikrap-core/src/main/java/org/gnikrap/utils/MapBuilder.java
// public final class MapBuilder<K, V> {
//   private final Map<K, V> map;
// 
//   public MapBuilder(Map<K, V> map) {
//     this.map = map;
//   }
// 
//   public MapBuilder<K, V> put(K k, V v) {
//     map.put(k, v);
//     return this;
//   }
// 
//   public Map<K, V> build() {
//     return map;
//   }
// 
//   public static final <K, V> MapBuilder<K, V> buildHashMap(K k, V v) {
//     return new MapBuilder<K, V>(new HashMap<K, V>()).put(k, v);
//   }
// 
//   public static final <K, V> MapBuilder<K, V> buildTreeMapBuilder() {
//     return new MapBuilder<K, V>(new TreeMap<K, V>());
//   }
// }


// Path: gnikrap-core/src/main/java/org/gnikrap/script/ev3api/SimpleEV3IRSensor.java
import lejos.hardware.port.Port;
import lejos.hardware.sensor.EV3IRSensor;
import lejos.hardware.sensor.SensorMode;
import org.gnikrap.utils.MapBuilder;
import org.gnikrap.utils.ScriptApi;

  @ScriptApi
  public void setChannel(int channel) throws EV3ScriptException {
    checkChannel(channel);
    this.channel = channel;
  }

  @ScriptApi
  public RemoteCommandResult getRemoteCommand() {
    int temp = delegate.getRemoteCommand(channel - 1); // channel 0-based
    logger.log(EV3Constants.IR_SENSOR_REMOTE, temp);
    return new RemoteCommandResult(temp);
  }

  @ScriptApi
  public float getDistance() {
    distanceMode.fetchSample(distanceSample, 0);
    float result = distanceSample[0];
    logger.log(EV3Constants.IR_SENSOR_DISTANCE, result);
    return result;
  }

  @ScriptApi
  public SeekBeaconResult seekBeacon() {
    seekMode.fetchSample(seekSample, 0);
    // TODO: Something to log ?!
    return new SeekBeaconResult(seekSample, channel);
  }

  protected static void checkChannel(int channel) throws EV3ScriptException {
    if (channel < 1 || channel > 4) {
      throw new EV3ScriptException(EV3ScriptException.INVALID_CHANNEL_VALUE, MapBuilder.buildHashMap("channel", Integer.toString(channel)).build());