Exemple #1
0
 boolean isEnabled(long m) {
   if (enabledMechanisms != null) {
     return enabledMechanisms.contains(Long.valueOf(m));
   }
   if (disabledMechanisms != null) {
     return !disabledMechanisms.contains(Long.valueOf(m));
   }
   return true;
 }
  public void testP2OMap() {
    // Long-long
    TLongObjectHashMap<Long> lomap = new TLongObjectHashMap<Long>();
    assertTrue(serializesCorrectly(lomap, "p2o-l-1"));
    lomap.put(0, Long.valueOf(1));
    assertTrue(serializesCorrectly(lomap, "p2o-l-2"));
    lomap.put(Long.MIN_VALUE, Long.valueOf(Long.MIN_VALUE));
    assertTrue(serializesCorrectly(lomap, "p2o-l-3"));
    lomap.put(Long.MAX_VALUE, Long.valueOf(Long.MAX_VALUE));
    assertTrue(serializesCorrectly(lomap, "p2o-l-4"));

    // Int-int
    TIntObjectHashMap<Integer> iomap = new TIntObjectHashMap<Integer>();
    assertTrue(serializesCorrectly(iomap, "p2o-i-1"));
    iomap.put(0, Integer.valueOf(1));
    assertTrue(serializesCorrectly(iomap, "p2o-i-2"));
    iomap.put(Integer.MIN_VALUE, Integer.valueOf(Integer.MIN_VALUE));
    assertTrue(serializesCorrectly(iomap, "p2o-i-3"));
    iomap.put(Integer.MAX_VALUE, Integer.valueOf(Integer.MAX_VALUE));
    assertTrue(serializesCorrectly(iomap, "p2o-i-4"));

    // Double-double
    TDoubleObjectHashMap<Double> domap = new TDoubleObjectHashMap<Double>();
    assertTrue(serializesCorrectly(domap, "p2o-d-1"));
    domap.put(0, Double.valueOf(1));
    assertTrue(serializesCorrectly(domap, "p2o-d-2"));
    domap.put(Double.MIN_VALUE, Double.valueOf(Double.MIN_VALUE));
    assertTrue(serializesCorrectly(domap, "p2o-d-3"));
    domap.put(Double.MAX_VALUE, Double.valueOf(Double.MAX_VALUE));
    assertTrue(serializesCorrectly(domap, "p2o-d-4"));
    domap.put(Double.POSITIVE_INFINITY, Double.valueOf(Double.POSITIVE_INFINITY));
    assertTrue(serializesCorrectly(domap, "p2o-d-5"));
    domap.put(Double.NEGATIVE_INFINITY, Double.valueOf(Double.NEGATIVE_INFINITY));
    assertTrue(serializesCorrectly(domap, "p2o-d-6"));
    // NOTE: trove doesn't deal well with NaN
    //        ddmap.put( Double.NaN, Double.NaN );
    //        assertTrue( serializesCorrectly( ddmap ) );

    // Float-float
    TFloatObjectHashMap<Float> fomap = new TFloatObjectHashMap<Float>();
    assertTrue(serializesCorrectly(fomap, "p2o-f-1"));
    fomap.put(0, Float.valueOf(1));
    assertTrue(serializesCorrectly(fomap, "p2o-f-2"));
    fomap.put(Float.MIN_VALUE, Float.valueOf(Float.MIN_VALUE));
    assertTrue(serializesCorrectly(fomap, "p2o-f-3"));
    fomap.put(Float.MAX_VALUE, Float.valueOf(Float.MAX_VALUE));
    assertTrue(serializesCorrectly(fomap, "p2o-f-4"));
    fomap.put(Float.POSITIVE_INFINITY, Float.valueOf(Float.POSITIVE_INFINITY));
    assertTrue(serializesCorrectly(fomap, "p2o-f-5"));
    fomap.put(Float.NEGATIVE_INFINITY, Float.valueOf(Float.NEGATIVE_INFINITY));
    assertTrue(serializesCorrectly(fomap, "p2o-f-6"));
    // NOTE: trove doesn't deal well with NaN
    //        ffmap.put( Float.NaN, Float.NaN );
    //        assertTrue( serializesCorrectly( ffmap ) );
  }
  public void testO2PMap() {
    // Long-long
    TObjectLongHashMap<Long> olmap = new TObjectLongHashMap<Long>();
    assertTrue(serializesCorrectly(olmap, "o2p-l-1"));
    olmap.put(Long.valueOf(0), 1);
    assertTrue(serializesCorrectly(olmap, "o2p-l-2"));
    olmap.put(Long.valueOf(Long.MIN_VALUE), Long.MIN_VALUE);
    assertTrue(serializesCorrectly(olmap, "o2p-l-3"));
    olmap.put(Long.valueOf(Long.MAX_VALUE), Long.MAX_VALUE);
    assertTrue(serializesCorrectly(olmap, "o2p-l-4"));

    // Int-int
    TObjectIntHashMap<Integer> oimap = new TObjectIntHashMap<Integer>();
    assertTrue(serializesCorrectly(oimap, "o2p-i-1"));
    oimap.put(Integer.valueOf(0), 1);
    assertTrue(serializesCorrectly(oimap, "o2p-i-2"));
    oimap.put(Integer.valueOf(Integer.MIN_VALUE), Integer.MIN_VALUE);
    assertTrue(serializesCorrectly(oimap, "o2p-i-3"));
    oimap.put(Integer.valueOf(Integer.MAX_VALUE), Integer.MAX_VALUE);
    assertTrue(serializesCorrectly(oimap, "o2p-i-4"));

    // Double-double
    TObjectDoubleHashMap<Double> odmap = new TObjectDoubleHashMap<Double>();
    assertTrue(serializesCorrectly(odmap, "o2p-d-1"));
    odmap.put(Double.valueOf(0), 1);
    assertTrue(serializesCorrectly(odmap, "o2p-d-2"));
    odmap.put(Double.valueOf(Double.MIN_VALUE), Double.MIN_VALUE);
    assertTrue(serializesCorrectly(odmap, "o2p-d-3"));
    odmap.put(Double.valueOf(Double.MAX_VALUE), Double.MAX_VALUE);
    assertTrue(serializesCorrectly(odmap, "o2p-d-4"));
    odmap.put(Double.valueOf(Double.POSITIVE_INFINITY), Double.POSITIVE_INFINITY);
    assertTrue(serializesCorrectly(odmap, "o2p-d-5"));
    odmap.put(Double.valueOf(Double.NEGATIVE_INFINITY), Double.NEGATIVE_INFINITY);
    assertTrue(serializesCorrectly(odmap, "o2p-d-6"));
    // NOTE: trove doesn't deal well with NaN
    //        ddmap.put( Double.NaN, Double.NaN );
    //        assertTrue( serializesCorrectly( ddmap ) );

    // Float-float
    TObjectFloatHashMap<Float> ofmap = new TObjectFloatHashMap<Float>();
    assertTrue(serializesCorrectly(ofmap, "o2p-f-1"));
    ofmap.put(Float.valueOf(0), 1);
    assertTrue(serializesCorrectly(ofmap, "o2p-f-2"));
    ofmap.put(Float.valueOf(Float.MIN_VALUE), Float.MIN_VALUE);
    assertTrue(serializesCorrectly(ofmap, "o2p-f-3"));
    ofmap.put(Float.valueOf(Float.MAX_VALUE), Float.MAX_VALUE);
    assertTrue(serializesCorrectly(ofmap, "o2p-f-4"));
    ofmap.put(Float.valueOf(Float.POSITIVE_INFINITY), Float.POSITIVE_INFINITY);
    assertTrue(serializesCorrectly(ofmap, "o2p-f-5"));
    ofmap.put(Float.valueOf(Float.NEGATIVE_INFINITY), Float.NEGATIVE_INFINITY);
    assertTrue(serializesCorrectly(ofmap, "o2p-f-6"));
    // NOTE: trove doesn't deal well with NaN
    //        ffmap.put( Float.NaN, Float.NaN );
    //        assertTrue( serializesCorrectly( ffmap ) );
  }
 public void occurred(String operationName) {
   if (this.profileWeight < SessionProfiler.NORMAL) {
     return;
   }
   synchronized (this.operationTimings) {
     Long occurred = (Long) this.operationTimings.get(operationName);
     if (occurred == null) {
       this.operationTimings.put(operationName, Long.valueOf(1));
     } else {
       this.operationTimings.put(operationName, Long.valueOf(occurred.longValue() + 1));
     }
   }
 }
Exemple #5
0
  private ReadProgress loadReadProgress(final ITweetFeed feed) {
    try {
      final BufferedReader is =
          new BufferedReader(new FileReader(Config.getStatProgressFilename()));
      final String line = is.readLine();

      final String[] split = line.split("\\s");

      return new ReadProgress(
          Long.valueOf(split[0]), Long.valueOf(split[1]), Integer.valueOf(split[2]));
    } catch (FileNotFoundException e) {
    } catch (IOException e) {
    }
    return null;
  }
Exemple #6
0
  static {
    String tmp;

    int max_elements = 500;
    long max_age = 5000L;

    try {
      tmp =
          Util.getProperty(new String[] {Global.UUID_CACHE_MAX_ELEMENTS}, null, null, false, "500");
      if (tmp != null) max_elements = Integer.valueOf(tmp);
    } catch (Throwable t) {
    }

    try {
      tmp = Util.getProperty(new String[] {Global.UUID_CACHE_MAX_AGE}, null, null, false, "5000");
      if (tmp != null) max_age = Long.valueOf(tmp);
    } catch (Throwable t) {
    }

    cache = new LazyRemovalCache<Address, String>(max_elements, max_age);

    /* Trying to get value of jgroups.print_uuids. PropertyPermission not granted if
     * running in an untrusted environment with JNLP */
    try {
      tmp = Util.getProperty(new String[] {Global.PRINT_UUIDS}, null, null, false, "false");
      print_uuids = Boolean.valueOf(tmp).booleanValue();
    } catch (SecurityException ex) {
    }
  }
Exemple #7
0
 @SuppressWarnings("LockAcquiredButNotSafelyReleased")
 protected void handleLock(String[] args) {
   String lockStr = args[0];
   String key = args[1];
   Lock lock = hazelcast.getLock(key);
   if (lockStr.equalsIgnoreCase("lock")) {
     lock.lock();
     println("true");
   } else if (lockStr.equalsIgnoreCase("unlock")) {
     lock.unlock();
     println("true");
   } else if (lockStr.equalsIgnoreCase("trylock")) {
     String timeout = args.length > 2 ? args[2] : null;
     if (timeout == null) {
       println(lock.tryLock());
     } else {
       long time = Long.valueOf(timeout);
       try {
         println(lock.tryLock(time, TimeUnit.SECONDS));
       } catch (InterruptedException e) {
         e.printStackTrace();
       }
     }
   }
 }
    @Override
    public void handleNotification(ExecutionNodeResult result) {
      // convert to a SubstepsTestProxy and a TestEvent class

      Long executionNodeId = Long.valueOf(result.getExecutionNodeId());

      SubstepsTestProxy testProxy = proxyMap.get(executionNodeId);

      log.debug("got notification: " + executionNodeId + " result: " + result.getResult());

      switch (result.getResult()) {
        case FAILED:
          {
            testProxy.setState(SubstepTestState.FAILED);
            break;
          }
        case IGNORED:
          {
            testProxy.setState(SubstepTestState.SKIPPED);
            break;
          }
        case NOT_INCLUDED:
          {
            testProxy.setState(SubstepTestState.SKIPPED);
            break;
          }
        case NOT_RUN:
          {
            testProxy.setState(SubstepTestState.NOT_RUN);
            break;
          }
        case RUNNING:
          {
            testProxy.setState(SubstepTestState.RUNNING);
            break;
          }
        case PASSED:
          {
            testProxy.setState(SubstepTestState.PASSED);
            break;
          }
        case NON_CRITICAL_FAILURE:
          {
            testProxy.setState(SubstepTestState.FAILED);
            break;
          }
        case PARSE_FAILURE:
          {
            testProxy.setState(SubstepTestState.FAILED);
            break;
          }
        case SETUP_TEARDOWN_FAILURE:
          {
            testProxy.setState(SubstepTestState.FAILED);
            break;
          }
      }

      eventsConsumer.onEvent(new StateChangedEvent(testProxy));
    }
Exemple #9
0
 private Set<Long> parseMechanisms(String keyword) throws IOException {
   checkDup(keyword);
   Set<Long> mechs = new HashSet<Long>();
   parseEquals();
   parseOpenBraces();
   while (true) {
     int token = nextToken();
     if (isCloseBraces(token)) {
       break;
     }
     if (token == TT_EOL) {
       continue;
     }
     if (token != TT_WORD) {
       throw excToken("Expected mechanism, read");
     }
     long mech = parseMechanism(st.sval);
     mechs.add(Long.valueOf(mech));
   }
   if (DEBUG) {
     System.out.print("mechanisms: [");
     for (Long mech : mechs) {
       System.out.print(Functions.getMechanismName(mech));
       System.out.print(", ");
     }
     System.out.println("]");
   }
   return mechs;
 }
  @Override
  public Number getNumberValue() throws IOException, JsonParseException {
    if (_numTypesValid == NR_UNKNOWN) {
      _parseNumericValue(NR_UNKNOWN); // will also check event type
    }
    // Separate types for int types
    if (_currToken == JsonToken.VALUE_NUMBER_INT) {
      if ((_numTypesValid & NR_INT) != 0) {
        return Integer.valueOf(_numberInt);
      }
      if ((_numTypesValid & NR_LONG) != 0) {
        return Long.valueOf(_numberLong);
      }
      if ((_numTypesValid & NR_BIGINT) != 0) {
        return _numberBigInt;
      }
      // Shouldn't get this far but if we do
      return _numberBigDecimal;
    }

    /* And then floating point types. But here optimal type
     * needs to be big decimal, to avoid losing any data?
     */
    if ((_numTypesValid & NR_BIGDECIMAL) != 0) {
      return _numberBigDecimal;
    }
    if ((_numTypesValid & NR_DOUBLE) == 0) { // sanity check
      _throwInternal();
    }
    return Double.valueOf(_numberDouble);
  }
Exemple #11
0
 private static Object parseValue(String value, Prop p, Class type) {
   Object v = value;
   if (type.isArray()) {
     StringTokenizer st = new StringTokenizer(value, ",");
     Class ctype = type.getComponentType();
     v = Array.newInstance(ctype, st.countTokens());
     for (int i = 0; st.hasMoreTokens(); i++)
       Array.set(v, i, parseValue(st.nextToken(), p, ctype));
   } else if (type == boolean.class) {
     v = Boolean.valueOf(value);
   } else if (type == double.class) {
     v = Double.valueOf(value);
   } else if (type == int.class) {
     v = Integer.valueOf(value);
   } else if (p.field.isAnnotationPresent(TimeIntervalProp.class)) {
     if (value.endsWith("s")) {
       v = (long) (Double.parseDouble(value.substring(0, value.length() - 1)) * SEC);
     } else if (value.endsWith("m")) {
       v = (long) (Double.parseDouble(value.substring(0, value.length() - 1)) * MIN);
     } else {
       v = Long.valueOf(value);
     }
   }
   return v;
 }
 /** Log the results to the session's log (System.out). */
 public void dumpResults() {
   this.lastDumpTime = System.currentTimeMillis();
   StringWriter writer = new StringWriter();
   writer.write("\nPerformance Monitor:");
   writer.write(String.valueOf(this.lastDumpTime));
   writer.write("\nOperation\tValue (ns)\n");
   Set<String> operations = new TreeSet<String>(this.operationTimings.keySet());
   NumberFormat formater = NumberFormat.getInstance();
   for (String operation : operations) {
     Object value = this.operationTimings.get(operation);
     if (value == null) {
       value = Long.valueOf(0);
     }
     writer.write(operation);
     writer.write("\t");
     if (value instanceof Long) {
       writer.write(formater.format(value));
     } else {
       writer.write(value.toString());
     }
     writer.write("\n");
   }
   try {
     this.session.getLog().write(writer.toString());
     this.session.getLog().flush();
   } catch (IOException error) {
     // ignore
   }
 }
 public static void main(String[] args) throws Exception {
   long i = 0;
   long a = Long.MAX_VALUE;
   long max = Long.valueOf(args[0]);
   System.out.println(max);
   while ((i++) < max) a = a - i;
   System.out.println(a);
 }
Exemple #14
0
  public static void removeProperty() {
    String id = params.get("id");
    Prop p = Prop.findById(Long.valueOf(id));
    List<Specification> specifications =
        Specification.em()
            .createQuery(
                "select r from Specification r join fetch r.properties s where s.id="
                    + Long.valueOf(id),
                Specification.class)
            .getResultList();

    for (Specification spec : specifications) {
      spec.properties.remove(p);
      spec.save();
    }
    if (p != null) p.delete();
    renderText(id);
  }
Exemple #15
0
  public static void removeSpec() {
    String id = params.get("id");
    Specification spec = Specification.findById(Long.valueOf(id));
    List<Request> requests =
        Request.em()
            .createQuery(
                "select r from Request r join fetch r.specifications s where s.id="
                    + Long.valueOf(id),
                Request.class)
            .getResultList();

    for (Request req : requests) {
      req.specifications.remove(spec);
      req.save();
    }
    if (spec != null) spec.delete();
    renderText(id);
  }
Exemple #16
0
  public static void toubiao() {
    String username = session.get("username");
    if (username != null) {
      User user = User.getByUserName(username);
      Profile profile = Profile.find("user.id=?", user.id).first();

      String payStyle = params.get("payStyle");
      String invoice = params.get("invoice");
      String comments = params.get("comments");
      String requestS = params.get("request");

      Request request = Request.findById(Long.valueOf(requestS));
      Toubiao toubiao = null;
      toubiao = Toubiao.find("request.id=? and profile.id=?", request.id, profile.id).first();
      if (toubiao == null) {
        toubiao = new Toubiao();
      }
      toubiao.profile = profile;
      toubiao.user = user;
      toubiao.request = request;
      toubiao.payStyle = payStyle;
      toubiao.invoice = invoice;
      toubiao.comments = comments;
      toubiao.again = false;
      toubiao.save();

      String price = "0";
      String price2 = "0";
      String price3 = "0";
      Baojia baojia = null;
      for (Specification spec : request.specifications) {
        price = params.get("price" + spec.id);
        price2 = params.get("price" + spec.id + "-2");
        price3 = params.get("price" + spec.id + "-3");
        baojia = Baojia.find("toubiao.id=? and specification.id=?", toubiao.id, spec.id).first();
        if (baojia == null) {
          baojia = new Baojia();
          baojia.toubiao = toubiao;
          baojia.specification = spec;
        }
        if (price != null && !"".equals(price) && !"0".equals(price))
          baojia.price = Double.valueOf(price);
        if (price2 != null && !"".equals(price2) && !"0".equals(price2))
          baojia.secondPrice = Double.valueOf(price2);
        if (price3 != null && !"".equals(price3) && !"0".equals(price3))
          baojia.thirdPrice = Double.valueOf(price3);
        baojia.save();

        if (!toubiao.baojias.contains(baojia)) {

          toubiao.baojias.add(baojia);
          toubiao.save();
        }
      }
    }
    redirect("/");
  }
Exemple #17
0
 public static void remove() {
   Long id = Long.valueOf(params.get("id"));
   Files files = Files.findById(id);
   if (files.image.getFile().exists()) {
     files.image.getFile().delete();
   }
   files.delete();
   renderText("");
 }
Exemple #18
0
 public Long readBuf(Buf buf, long n) {
   try {
     long read = buf.pipeFrom(in, n);
     if (read < 0) return null;
     return Long.valueOf(read);
   } catch (IOException e) {
     throw IOErr.make(e);
   }
 }
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    super.onActivityResult(requestCode, resultCode, data);

    if (resultCode == Activity.RESULT_OK) {
      String sdStatus = Environment.getExternalStorageState();
      if (!sdStatus.equals(Environment.MEDIA_MOUNTED)) { // 检测sd是否可用
        Log.i("TestFile", "SD card is not avaiable/writeable right now.");
        return;
      }
      String name =
          new DateFormat().format("yyyyMMdd_hhmmss", Calendar.getInstance(Locale.CHINA)) + ".jpg";
      Toast.makeText(this, name, Toast.LENGTH_LONG).show();
      Bundle bundle = data.getExtras();
      Bitmap bitmap = (Bitmap) bundle.get("data"); // 获取相机返回的数据,并转换为Bitmap图片格式

      FileOutputStream b = null;
      File file = new File("/sdcard/myImage/");
      if (!file.exists()) file.mkdirs(); // 创建文件夹

      String fileName = "/sdcard/myImage/" + name;
      File photofile = new File(fileName);
      if (!photofile.exists()) {
        try {
          photofile.createNewFile();
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
      try {
        b = new FileOutputStream(photofile);
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, b); // 把数据写入文件
      } catch (Exception e) {
        e.printStackTrace();
      } finally {
        try {
          b.flush();
          b.close();
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
      // 动态的改变gridview中的一个Item的内容
      bitmapList.set(currentIndex, bitmap);
      myGalleryAdapter.notifyDataSetChanged();
      updatePhoto(
          Long.valueOf(phoneNumberToId.get(phoneNumber.get(currentIndex))), bitmapToBytes(bitmap));
      //            ((ImageView) findViewById(R.id.imageView)).setImageBitmap(bitmap);//
      // 将图片显示在ImageView里
      Intent intent = new Intent(ContactActivity.this, ContactActivity.class);
      this.startActivity(intent);
      this.finish();
    }
  }
Exemple #20
0
  /**
   * Overrides the parent implementation to provide a more efficient mechanism for generating
   * primary keys, while generating the primary key support on the fly.
   *
   * @param count the batch size
   * @param entity the entity requesting primary keys
   * @param channel open JDBCChannel
   * @return NSArray of NSDictionary where each dictionary corresponds to a unique primary key value
   */
  public NSArray newPrimaryKeys(int count, EOEntity entity, JDBCChannel channel) {
    if (isPrimaryKeyGenerationNotSupported(entity)) {
      return null;
    }

    EOAttribute attribute = (EOAttribute) entity.primaryKeyAttributes().lastObject();
    String attrName = attribute.name();
    boolean isIntType = "i".equals(attribute.valueType());

    NSMutableArray results = new NSMutableArray(count);
    String sequenceName = sequenceNameForEntity(entity);
    DB2Expression expression = new DB2Expression(entity);

    boolean succeeded = false;
    for (int tries = 0; !succeeded && tries < 2; tries++) {
      while (results.count() < count) {
        try {
          StringBuffer sql = new StringBuffer();
          sql.append("SELECT ");
          sql.append("next value for " + sequenceName + " AS KEY");
          sql.append(" from sysibm.sysdummy1");
          expression.setStatement(sql.toString());
          channel.evaluateExpression(expression);
          try {
            NSDictionary row;
            while ((row = channel.fetchRow()) != null) {
              Enumeration pksEnum = row.allValues().objectEnumerator();
              while (pksEnum.hasMoreElements()) {
                Number pkObj = (Number) pksEnum.nextElement();
                Number pk;
                if (isIntType) {
                  pk = Integer.valueOf(pkObj.intValue());
                } else {
                  pk = Long.valueOf(pkObj.longValue());
                }
                results.addObject(new NSDictionary(pk, attrName));
              }
            }
          } finally {
            channel.cancelFetch();
          }
          succeeded = true;
        } catch (JDBCAdaptorException ex) {
          throw ex;
        }
      }
    }

    if (results.count() != count) {
      throw new IllegalStateException(
          "Unable to generate primary keys from the sequence for " + entity + ".");
    }

    return results;
  }
Exemple #21
0
 public boolean hasIntParam(String key) {
   if (this.hasParam(key)) {
     try {
       Long val = Long.valueOf(this.params.get(key));
       if (val != null) return (true);
     } catch (NumberFormatException ex) {
       // Nothing...
     }
   }
   return (false);
 }
Exemple #22
0
 private boolean parseBody() {
   String[] parts = this.body.split("&");
   for (String part : parts) {
     String[] subParts = part.split("=");
     String key = subParts[0];
     String value = subParts[1];
     if ("bucket".equals(key)) {
       this.bucket = value;
     } else if ("object".equals(key)) {
       this.object = URLDecoder.decode(value);
     } else if ("userId".equals(key)) {
       this.userId = Long.valueOf(value);
     } else if ("transcode".equals(key)) {
       this.transcode = Long.valueOf(value) == 1;
     }
   }
   return (!StringUtils.isEmpty(this.bucket)
       && !StringUtils.isEmpty(this.object)
       && this.userId != 0);
 }
Exemple #23
0
 protected void handleQPoll(String[] args) {
   long timeout = 0;
   if (args.length > 1) {
     timeout = Long.valueOf(args[1]);
   }
   try {
     println(getQueue().poll(timeout, TimeUnit.SECONDS));
   } catch (InterruptedException e) {
     e.printStackTrace();
   }
 }
  /** INTERNAL: End the operation timing. */
  public void endOperationProfile(String operationName) {
    if (this.profileWeight < SessionProfiler.HEAVY) {
      return;
    }
    long endTime = System.nanoTime();
    Long startTime = getOperationStartTimes().get(operationName);
    if (startTime == null) {
      return;
    }
    long time = endTime - startTime.longValue();

    synchronized (this.operationTimings) {
      Long totalTime = (Long) this.operationTimings.get(operationName);
      if (totalTime == null) {
        this.operationTimings.put(operationName, Long.valueOf(time));
      } else {
        this.operationTimings.put(operationName, Long.valueOf(totalTime.longValue() + time));
      }
    }
  }
Exemple #25
0
 protected void handleQOffer(String[] args) {
   long timeout = 0;
   if (args.length > 2) {
     timeout = Long.valueOf(args[2]);
   }
   try {
     boolean offered = getQueue().offer(args[1], timeout, TimeUnit.SECONDS);
     println(offered);
   } catch (InterruptedException e) {
     e.printStackTrace();
   }
 }
 /** {@inheritDoc} */
 @SuppressWarnings({"SuspiciousMethodCalls"})
 public boolean retainAll(Collection<?> collection) {
   boolean modified = false;
   TLongIterator iter = iterator();
   while (iter.hasNext()) {
     if (!collection.contains(Long.valueOf(iter.next()))) {
       iter.remove();
       modified = true;
     }
   }
   return modified;
 }
  public final void testNonBlockingIdentityHashMapSize() {
    NonBlockingIdentityHashMap<Long, String> items = new NonBlockingIdentityHashMap<Long, String>();
    items.put(Long.valueOf(100), "100");
    items.put(Long.valueOf(101), "101");

    assertEquals("keySet().size()", 2, items.keySet().size());
    assertTrue("keySet().contains(100)", items.keySet().contains(Long.valueOf(100)));
    assertTrue("keySet().contains(101)", items.keySet().contains(Long.valueOf(101)));

    assertEquals("values().size()", 2, items.values().size());
    assertTrue("values().contains(\"100\")", items.values().contains("100"));
    assertTrue("values().contains(\"101\")", items.values().contains("101"));

    assertEquals("entrySet().size()", 2, items.entrySet().size());
    boolean found100 = false;
    boolean found101 = false;
    for (Entry<Long, String> entry : items.entrySet()) {
      if (entry.getKey().equals(Long.valueOf(100))) {
        assertEquals("entry[100].getValue()==\"100\"", "100", entry.getValue());
        found100 = true;
      } else if (entry.getKey().equals(Long.valueOf(101))) {
        assertEquals("entry[101].getValue()==\"101\"", "101", entry.getValue());
        found101 = true;
      }
    }
    assertTrue("entrySet().contains([100])", found100);
    assertTrue("entrySet().contains([101])", found101);
  }
  /**
   * Retrieves long value from parameters map.
   *
   * @param key Key.
   * @param params Parameters map.
   * @param dfltVal Default value.
   * @return Long value from parameters map or {@code dfltVal} if null or not exists.
   * @throws GridException If parsing failed.
   */
  @Nullable
  private static Long longValue(String key, Map<String, Object> params, Long dfltVal)
      throws GridException {
    assert key != null;

    String val = (String) params.get(key);

    try {
      return val == null ? dfltVal : Long.valueOf(val);
    } catch (NumberFormatException ignore) {
      throw new GridException("Failed to parse parameter of Long type [" + key + "=" + val + "]");
    }
  }
Exemple #29
0
 protected void handleMapTryLock(String[] args) {
   String key = args[1];
   long time = (args.length > 2) ? Long.valueOf(args[2]) : 0;
   boolean locked = false;
   if (time == 0) locked = getMap().tryLock(key);
   else
     try {
       locked = getMap().tryLock(key, time, TimeUnit.SECONDS);
     } catch (InterruptedException e) {
       locked = false;
     }
   println(locked);
 }
Exemple #30
0
  public static void zbAgain() {
    String id = params.get("toubiaoid");
    String againComments = params.get("againComments");
    Toubiao toubiao = Toubiao.findById(Long.valueOf(id));
    toubiao.again = true;
    toubiao.againComments = againComments;
    toubiao.save();

    Request req = toubiao.request;
    req.status = 2;
    req.save();
    redirect("/vender/tblist?id=" + id);
  }