Esempio n. 1
0
 @Test
 public void testTable() {
   HashBasedTable<Integer, Integer, Integer> table = HashBasedTable.create();
   table.put(1, 1, 1);
   table.put(1, 2, 2);
   table.put(1, 3, 3);
   table.put(2, 1, 4);
   table.put(2, 2, 5);
   table.put(2, 3, 6);
   assert table.containsRow(1);
   assert table.containsColumn(2);
   assert table.row(1).get(3) == 3;
 }
Esempio n. 2
0
  @Test
  public void testHashBasedTable() {
    HashBasedTable<Integer, Integer, String> table = HashBasedTable.create();

    for (int row = 0; row < 5; row++) {
      for (int column = 0; column < 10; column++) {
        table.put(row, column, row + "_" + column);
      }
    }

    System.out.println(table.rowMap().toString());
  }
  private void handleIncomingConfirmableCoapRequest(ChannelHandlerContext ctx, MessageEvent me) {
    InetSocketAddress remoteEndpoint = (InetSocketAddress) me.getRemoteAddress();
    CoapMessage coapMessage = (CoapMessage) me.getMessage();

    IncomingReliableMessageExchange newMessageExchange =
        new IncomingReliableMessageExchange(remoteEndpoint, coapMessage.getMessageID());

    IncomingMessageExchange oldMessageExchange =
        ongoingMessageExchanges.get(remoteEndpoint, coapMessage.getMessageID());

    // Check if there is an ongoing
    if (oldMessageExchange != null) {

      if (oldMessageExchange instanceof IncomingReliableMessageExchange) {

        // if the old message exchange is reliable and the empty ACK was already sent send another
        // empty ACK
        if (((IncomingReliableMessageExchange) oldMessageExchange).isAcknowledgementSent())
          writeEmptyAcknowledgement(remoteEndpoint, coapMessage.getMessageID());

      }

      // if the old message was unreliable and the duplicate message is confirmable send empty ACK
      else writeEmptyAcknowledgement(remoteEndpoint, coapMessage.getMessageID());

      // As the message is already being processed there is nothing more to do
      return;
    }

    // try to add new reliable message exchange
    boolean added = false;
    synchronized (monitor) {
      Long time = System.currentTimeMillis() + MIN_EMPTY_ACK_DELAY_MILLIS;

      // Add message exchange to set of ongoing exchanges to detect duplicates
      if (!ongoingMessageExchanges.contains(remoteEndpoint, coapMessage.getMessageID())) {
        ongoingMessageExchanges.put(remoteEndpoint, coapMessage.getMessageID(), newMessageExchange);
        added = true;
      }

      // If the scheduling of the empty ACK does not work then it was already scheduled
      if (!emptyAcknowledgementSchedule.put(time, newMessageExchange)) {
        log.error("Could not schedule empty ACK for message: {}", coapMessage);
        ongoingMessageExchanges.remove(remoteEndpoint, coapMessage.getMessageID());
        added = false;
      }
    }

    // everything is fine, so further process message
    if (added) ctx.sendUpstream(me);
  }
 /**
  * Filter out any employees in this Supervisor emp group that are not under this supervisor during
  * the given dateRange.
  *
  * @param dateRange Range<LocalDate>
  */
 public void filterActiveEmployeesByDate(Range<LocalDate> dateRange) {
   this.setPrimaryEmployees(
       this.getPrimaryEmployees()
           .values()
           .stream()
           .filter(supInfo -> isSupInfoInRange(supInfo, dateRange))
           .collect(Collectors.toMap(EmployeeSupInfo::getEmpId, Function.identity())));
   this.setOverrideEmployees(
       this.getOverrideEmployees()
           .values()
           .stream()
           .filter(supInfo -> isSupInfoInRange(supInfo, dateRange))
           .collect(Collectors.toMap(EmployeeSupInfo::getEmpId, Function.identity())));
   HashBasedTable<Integer, Integer, EmployeeSupInfo> filteredSupOverrideEmps =
       HashBasedTable.create();
   this.supOverrideEmployees
       .values()
       .stream()
       .filter(supInfo -> isSupInfoInRange(supInfo, dateRange))
       .forEach(
           supInfo ->
               filteredSupOverrideEmps.put(supInfo.getSupId(), supInfo.getEmpId(), supInfo));
   this.supOverrideEmployees = filteredSupOverrideEmps;
 }
  private void handleIncomingNonConfirmableMessage(ChannelHandlerContext ctx, MessageEvent me) {
    InetSocketAddress remoteEndpoint = (InetSocketAddress) me.getRemoteAddress();
    CoapMessage coapMessage = (CoapMessage) me.getMessage();

    boolean isDuplicate = true;

    if (!ongoingMessageExchanges.contains(remoteEndpoint, coapMessage.getMessageID())) {
      IncomingMessageExchange messageExchange =
          new IncomingMessageExchange(remoteEndpoint, coapMessage.getMessageID());

      synchronized (monitor) {
        if (!ongoingMessageExchanges.contains(remoteEndpoint, coapMessage.getMessageID())) {
          ongoingMessageExchanges.put(remoteEndpoint, coapMessage.getMessageID(), messageExchange);

          isDuplicate = false;
        }
      }

      ctx.sendUpstream(me);
    }

    if (isDuplicate)
      log.info("Received duplicate (non-confirmable). IGNORE! (Message: {})", coapMessage);
  }
  private void initialize() {

    // ert1 = earth geometry object
    // dThreshold = threshold distance
    // ranDist = distances range
    // ranTime = time range
    // ranDirect = directions range
    // i1 = counter
    // rgdSum = row sums

    double dThreshold;
    EarthGeometry ert1;
    Range<Double> ranDist;
    Range<Double> ranTime;
    Range<Double> ranDirect;
    int i1;
    double rgdSum[];

    // initializing mocked data
    rgdLat = new double[] {45., 46., 47., 48.};
    rgdLon = new double[] {-110., -109., -108., -107.};
    rgdPoints = new double[rgdLat.length * rgdLat.length][2];
    i1 = 0;
    for (int i = 0; i < rgdLat.length; i++) {
      for (int j = 0; j < rgdLat.length; j++) {
        rgdPoints[i1][0] = rgdLat[i];
        rgdPoints[i1][1] = rgdLon[j];
        i1++;
      }
    }

    rgdAbund = new double[2][rgdPoints.length];
    tblWeight = HashBasedTable.create(4, 4);
    dThreshold = 150.;

    ert1 = new EarthGeometry();
    rgdSum = new double[rgdPoints.length];
    for (int i = 0; i < rgdPoints.length; i++) {
      for (int j = 0; j < rgdPoints.length; j++) {
        if (i != j
            && ert1.orthodromicDistanceWGS84(
                    rgdPoints[i][0], rgdPoints[i][1], rgdPoints[j][0], rgdPoints[j][1])
                < dThreshold) {
          tblWeight.put(i, j, 1.);
          rgdSum[i] += 1.;
        } else {
          tblWeight.put(i, j, 0.);
        }
      }
      rgdAbund[0][i] = ((double) i) / 20.;
      rgdAbund[1][i] = (((double) i) % 4.) / 4.;
    }

    for (int i = 0; i < rgdPoints.length; i++) {
      for (int j = 0; j < rgdPoints.length; j++) {
        if (rgdSum[i] > 0) {
          tblWeight.put(i, j, tblWeight.get(i, j) / rgdSum[i]);
        }
      }
    }

    // loading spatial weights object from file
    ranDist = Range.closed(0., dThreshold);
    ranTime = Range.closed(0., 12.);
    ranDirect = Range.closed(0., 360.);
    bio1 =
        new BiomIO(
            "/home/jladau/Desktop/Data/Microbial_Community_Samples/ValidationData.NA.NA.Ladau.biom");

    try {
      spw1 =
          new SpatialWeightsMatrix(
              bio1, ranDist, ranDirect, ranTime, "binary", "latitude-longitude", false);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
 public void addCrossFeature(int i, int j, String f) {
   if (!crossFactors.contains(i, j)) {
     crossFactors.put(i, j, new Factor());
   }
   crossFactors.get(i, j).add(f);
 }