/** {@inheritDoc} */
 public void putAll(Map<? extends Integer, ? extends Integer> map) {
   ensureCapacity(map.size());
   // could optimize this for cases when map instanceof THashMap
   for (Map.Entry<? extends Integer, ? extends Integer> entry : map.entrySet()) {
     this.put(entry.getKey().intValue(), entry.getValue().intValue());
   }
 }
Example #2
1
 private Map<String, Object> query(HttpServletRequest req) {
   final Map<String, Object> map = new HashMap<>();
   for (Map.Entry<String, String[]> entry : req.getParameterMap().entrySet()) {
     map.put(entry.getKey(), entry.getValue());
   }
   return map;
 }
  @Override
  public final void runBare() throws Throwable {
    // Patch a bug with maven that does not pass properly the system property
    // with an empty value
    if ("org.hsqldb.jdbcDriver".equals(System.getProperty("gatein.test.datasource.driver"))) {
      System.setProperty("gatein.test.datasource.password", "");
    }

    //
    log.info("Running unit test:" + getName());
    for (Map.Entry<?, ?> entry : System.getProperties().entrySet()) {
      if (entry.getKey() instanceof String) {
        String key = (String) entry.getKey();
        log.debug(key + "=" + entry.getValue());
      }
    }

    //
    beforeRunBare();

    //
    try {
      super.runBare();
      log.info("Unit test " + getName() + " completed");
    } catch (Throwable throwable) {
      log.error("Unit test " + getName() + " did not complete", throwable);

      //
      throw throwable;
    } finally {
      afterRunBare();
    }
  }
  /**
   * Compares the specified Object with this Map for equality, as per the definition in the Map
   * interface.
   *
   * @param o object to be compared for equality with this hashtable
   * @return true if the specified Object is equal to this Map
   * @see Map#equals(Object)
   * @since 1.2
   */
  public synchronized boolean equals(Object o) {
    if (o == this) return true;

    if (!(o instanceof Map)) return false;
    Map<?, ?> t = (Map<?, ?>) o;
    if (t.size() != size()) return false;

    try {
      for (Map.Entry<K, V> e : entrySet()) {
        K key = e.getKey();
        V value = e.getValue();
        if (value == null) {
          if (!(t.get(key) == null && t.containsKey(key))) return false;
        } else {
          if (!value.equals(t.get(key))) return false;
        }
      }
    } catch (ClassCastException unused) {
      return false;
    } catch (NullPointerException unused) {
      return false;
    }

    return true;
  }
Example #5
0
 /**
  * This method builds the custom data collections used on the form and populates the values from
  * the collection of AwardCustomData on the Award.
  *
  * @param customAttributeGroups
  */
 @SuppressWarnings("unchecked")
 public void buildCustomDataCollectionsOnExistingDocument(
     SortedMap<String, List> customAttributeGroups) {
   for (Map.Entry<String, CustomAttributeDocument> customAttributeDocumentEntry :
       getCustomAttributeDocuments().entrySet()) {
     T loopAwardCustomData = null;
     for (T awardCustomData : getCustomDataList()) {
       if (awardCustomData.getCustomAttributeId()
           == (long) customAttributeDocumentEntry.getValue().getCustomAttribute().getId()) {
         loopAwardCustomData = awardCustomData;
         break;
       }
     }
     if (loopAwardCustomData != null) {
       String groupName =
           getCustomAttributeDocuments()
               .get(loopAwardCustomData.getCustomAttributeId().toString())
               .getCustomAttribute()
               .getGroupName();
       List<CustomAttributeDocument> customAttributeDocumentList =
           customAttributeGroups.get(groupName);
       if (customAttributeDocumentList == null) {
         customAttributeDocumentList = new ArrayList<CustomAttributeDocument>();
         customAttributeGroups.put(groupName, customAttributeDocumentList);
       }
       customAttributeDocumentList.add(
           getCustomAttributeDocuments()
               .get(loopAwardCustomData.getCustomAttributeId().toString()));
       Collections.sort(customAttributeDocumentList, new LabelComparator());
     }
   }
 }
  @Override
  public Long getUniqueDevicesAcceptingPush(
      Company company, Date eventDate, Campaign campaign, Device device) {
    String query =
        "SELECT COUNT(DISTINCT b.macAddress) FROM BluetoothSend b WHERE (b.acceptStatus = ?1 OR b.sendStatus = ?2) AND b.eventDate BETWEEN ?3 AND ?4 AND b.company = ?5 ";
    int paramCount = 5;
    HashMap<Integer, Object> params = new HashMap<Integer, Object>();
    if (campaign != null) {
      paramCount++;
      query += " AND b.campaign = ?" + paramCount + " ";
      params.put(paramCount, campaign);
    }
    if (device != null) {
      paramCount++;
      query += " AND b.device = ?" + paramCount + " ";
      params.put(paramCount, device);
    }
    Query q = em.createQuery(query);

    q.setParameter(1, 1);
    q.setParameter(2, BluetoothSend.STATUS_ACCEPTED);
    q.setParameter(3, eventDate);
    q.setParameter(4, DateUtil.getEndOfDay(eventDate));
    q.setParameter(5, company);

    for (Map.Entry<Integer, Object> entry : params.entrySet()) {
      Integer paramId = entry.getKey();
      Object object = entry.getValue();
      q.setParameter(paramId, object);
    }

    Long countResult = (Long) q.getSingleResult();
    return countResult;
  }
  @Override
  public List<BluetoothFileSendSummary> fetchBluetoothFileSendSummaries(
      Date eventDate, Company company, Campaign campaign, Device device) {
    String query =
        "SELECT b FROM BluetoothFileSendSummary b WHERE b.eventDate BETWEEN ?1 AND ?2 AND b.company = ?3 ";
    int paramCount = 3;
    HashMap<Integer, Object> params = new HashMap<Integer, Object>();
    if (campaign != null) {
      paramCount++;
      query += " AND b.campaign = ?" + paramCount + " ";
      params.put(paramCount, campaign);
    }
    if (device != null) {
      paramCount++;
      query += " AND b.device = ?" + paramCount + " ";
      params.put(paramCount, device);
    }

    Query q = em.createQuery(query);
    q.setParameter(1, eventDate);
    q.setParameter(2, DateUtil.getEndOfDay(eventDate));
    q.setParameter(3, company);

    for (Map.Entry<Integer, Object> entry : params.entrySet()) {
      Integer paramId = entry.getKey();
      Object object = entry.getValue();
      q.setParameter(paramId, object);
    }

    List<BluetoothFileSendSummary> results = (List<BluetoothFileSendSummary>) q.getResultList();
    return results;
  }
Example #8
0
  public static void main(String[] args) {
    RestTemplate restTemplate = new RestTemplate();
    String getAccessTokenUrl =
        String.format(
            "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s",
            PropertyHolder.APPID, PropertyHolder.APPSECRET);
    String retData =
        restTemplate.getForObject(getAccessTokenUrl, String.class, new HashMap<String, Object>());
    System.out.println("[Acess Token returned data] " + retData);

    JSONObject jsonObject = JSON.parseObject(retData);
    String accessToken = jsonObject.getString("access_token");
    String jsapiTicketUrl =
        String.format(
            "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=%s&type=jsapi",
            accessToken);
    retData =
        restTemplate.getForObject(jsapiTicketUrl, String.class, new HashMap<String, Object>());
    System.out.println("[jsapiTicketUrl returned data] " + retData);

    jsonObject = JSON.parseObject(retData);
    String jsapi_ticket = jsonObject.getString("ticket");

    String url = "http://cai.songdatech.com/crab/?buy_type=card";
    Map<String, String> ret = sign(jsapi_ticket, url);
    for (Map.Entry entry : ret.entrySet()) {
      System.out.println(entry.getKey() + ", " + entry.getValue());
    }
  }
Example #9
0
    protected Object findNext() {
      if (indivIter.hasNext()) {
        return indivIter.next();
      }

      // While we have a current satisfier set or we can get one...
      while ((curSatisfiersIter != null) || mapIter.hasNext()) {
        while ((curSatisfiersIter != null) && curSatisfiersIter.hasNext()) {
          // continue through the satisfiers of the current POP app
          Object obj = curSatisfiersIter.next();
          if (!curExceptions.contains(obj)) {
            return obj;
          }
        }

        // If we get here, then we've run out of individual elements
        // and satisfiers of the current POP app
        curSatisfiersIter = null;
        if (mapIter.hasNext()) {
          Map.Entry entry = (Map.Entry) mapIter.next();
          NumberVar popApp = (NumberVar) entry.getKey();
          curSatisfiersIter = ((Set) entry.getValue()).iterator();
          curExceptions = (Set) popAppExceptions.get(popApp);
        }
      }

      return null;
    }
  private void copyCustomSettingsFrom(@NotNull CodeStyleSettings from) {
    synchronized (myCustomSettings) {
      myCustomSettings.clear();

      for (final CustomCodeStyleSettings settings : from.getCustomSettingsValues()) {
        addCustomSettings((CustomCodeStyleSettings) settings.clone());
      }

      FIELD_TYPE_TO_NAME.copyFrom(from.FIELD_TYPE_TO_NAME);
      STATIC_FIELD_TYPE_TO_NAME.copyFrom(from.STATIC_FIELD_TYPE_TO_NAME);
      PARAMETER_TYPE_TO_NAME.copyFrom(from.PARAMETER_TYPE_TO_NAME);
      LOCAL_VARIABLE_TYPE_TO_NAME.copyFrom(from.LOCAL_VARIABLE_TYPE_TO_NAME);

      PACKAGES_TO_USE_IMPORT_ON_DEMAND.copyFrom(from.PACKAGES_TO_USE_IMPORT_ON_DEMAND);
      IMPORT_LAYOUT_TABLE.copyFrom(from.IMPORT_LAYOUT_TABLE);

      OTHER_INDENT_OPTIONS.copyFrom(from.OTHER_INDENT_OPTIONS);

      myAdditionalIndentOptions.clear();
      for (Map.Entry<FileType, IndentOptions> optionEntry :
          from.myAdditionalIndentOptions.entrySet()) {
        IndentOptions options = optionEntry.getValue();
        myAdditionalIndentOptions.put(optionEntry.getKey(), (IndentOptions) options.clone());
      }

      myCommonSettingsManager = from.myCommonSettingsManager.clone(this);
    }
  }
  private void consolidateInvoices() {

    for (Invoice i : invoices) {
      for (LineItem l : i.getInvoice()) {
        String code = l.getProduct().getCode();
        int quant = l.getQuantity();
        double total = l.getTotal();
        double price = l.getProduct().getPrice();
        double[] sale = new double[3];
        if (salesOrder.containsKey(code)) {
          sale = salesOrder.get(code);
          sale[0] += quant;
          sale[1] += total;
        } else {
          sale[0] = quant;
          sale[1] = total;
        }
        sale[2] = 0;
        salesOrder.put(code, sale);
      }
    }

    Iterator<Map.Entry<String, double[]>> entries = salesOrder.entrySet().iterator();

    while (entries.hasNext()) {
      Map.Entry<String, double[]> entry = entries.next();
      String code = entry.getKey();
      double[] sale = entry.getValue();
      sale[2] = sale[1] / sale[0];
      salesOrder.put(code, sale);
    }
  }
  /**
   * Provides a “diff report” of how the two sets are similar and how they are different, comparing
   * the entries by some aspect.
   *
   * <p>The transformer is used to generate the value to use to compare the entries by. That is, the
   * entries are not compared by equals by an attribute or characteristic.
   *
   * <p>The transformer is expected to produce a unique value for each entry in a single set.
   * Behaviour is undefined if this condition is not met.
   *
   * @param left The set on the “left” side of the comparison.
   * @param right The set on the “right” side of the comparison.
   * @param compareBy Provides the value to compare entries from either side by
   * @param <T> The type of the entry objects
   * @return A representation of the difference
   */
  public static <T> SetDiff<T> diffSetsBy(
      Set<? extends T> left, Set<? extends T> right, Transformer<?, T> compareBy) {
    if (left == null) {
      throw new NullPointerException("'left' set is null");
    }
    if (right == null) {
      throw new NullPointerException("'right' set is null");
    }

    SetDiff<T> setDiff = new SetDiff<T>();

    Map<Object, T> indexedLeft = collectMap(left, compareBy);
    Map<Object, T> indexedRight = collectMap(right, compareBy);

    for (Map.Entry<Object, T> leftEntry : indexedLeft.entrySet()) {
      T rightValue = indexedRight.remove(leftEntry.getKey());
      if (rightValue == null) {
        setDiff.leftOnly.add(leftEntry.getValue());
      } else {
        Pair<T, T> pair = Pair.of(leftEntry.getValue(), rightValue);
        setDiff.common.add(pair);
      }
    }

    for (T rightValue : indexedRight.values()) {
      setDiff.rightOnly.add(rightValue);
    }

    return setDiff;
  }
  protected String preprocessTextResource(
      String publicName,
      String category,
      String defaultName,
      Map<String, String> pairs,
      boolean verbose,
      File publicRoot)
      throws IOException {
    URL u = locateResource(publicName, category, defaultName, verbose, publicRoot);
    InputStream inp = u.openStream();
    if (inp == null) {
      throw new RuntimeException("Jar corrupt? No " + defaultName + " resource!");
    }

    // read fully into memory
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    byte[] buffer = new byte[1024];
    int length;
    while ((length = inp.read(buffer)) != -1) {
      baos.write(buffer, 0, length);
    }

    // substitute
    String result = new String(baos.toByteArray());
    for (Map.Entry<String, String> e : pairs.entrySet()) {
      if (e.getValue() != null) {
        result = result.replace(e.getKey(), e.getValue());
      }
    }
    return result;
  }
Example #14
0
 public void setExports(Map definitions) {
   for (Iterator i = definitions.entrySet().iterator(); i.hasNext(); ) {
     Map.Entry entry = (Map.Entry) i.next();
     DefineTag def = (DefineTag) entry.getValue();
     addExport(def);
   }
 }
 /**
  * Prints a usage message to the given stream.
  *
  * @param out The output stream to write to.
  */
 public void printUsage(OutputStream out) {
   Formatter formatter = new Formatter(out);
   Set<CommandLineOption> orderedOptions = new TreeSet<CommandLineOption>(new OptionComparator());
   orderedOptions.addAll(optionsByString.values());
   Map<String, String> lines = new LinkedHashMap<String, String>();
   for (CommandLineOption option : orderedOptions) {
     Set<String> orderedOptionStrings = new TreeSet<String>(new OptionStringComparator());
     orderedOptionStrings.addAll(option.getOptions());
     List<String> prefixedStrings = new ArrayList<String>();
     for (String optionString : orderedOptionStrings) {
       if (optionString.length() == 1) {
         prefixedStrings.add("-" + optionString);
       } else {
         prefixedStrings.add("--" + optionString);
       }
     }
     lines.put(GUtil.join(prefixedStrings, ", "), GUtil.elvis(option.getDescription(), ""));
   }
   int max = 0;
   for (String optionStr : lines.keySet()) {
     max = Math.max(max, optionStr.length());
   }
   for (Map.Entry<String, String> entry : lines.entrySet()) {
     if (entry.getValue().length() == 0) {
       formatter.format("%s%n", entry.getKey());
     } else {
       formatter.format("%-" + max + "s  %s%n", entry.getKey(), entry.getValue());
     }
   }
   formatter.flush();
 }
Example #16
0
 private void initProcessingConfig(Map<String, ?> pConfig) {
   if (pConfig != null) {
     for (Map.Entry<String, ?> entry : pConfig.entrySet()) {
       setProcessingConfig(entry.getKey(), entry.getValue());
     }
   }
 }
  /**
   * convert service result object to JSON
   *
   * @param result
   * @return
   */
  public static JSONObject toJson(PsRecentServiceResult result) {
    JSONObject json = new JSONObject();

    if (result != null) {
      json.put(PsRecentServiceResult.ID, int2String(result.getId()));
      json.put(PsRecentServiceResult.SERVICE_RESULT_ID, int2String(result.getServiceResultId()));
      json.put(PsRecentServiceResult.JOB_ID, int2String(result.getJob_id()));
      json.put(PsRecentServiceResult.SERVICE_ID, int2String(result.getService_id()));
      json.put(PsRecentServiceResult.STATUS, result.getStatus());
      json.put(PsRecentServiceResult.MESSAGE, result.getMessage());

      json.put(PsRecentServiceResult.TIME, IsoDateConverter.dateToString(result.getTime()));

      JSONObject parameters = new JSONObject();
      TreeMap<String, Object> treeMap = result.getParameters();
      for (Map.Entry<String, Object> entry : treeMap.entrySet()) {
        String key = entry.getKey();
        Object value = entry.getValue();
        parameters.put(key, value);
      }
      json.put(PsRecentServiceResult.PARAMETERS, parameters);
    }

    return json;
  }
Example #18
0
 public PropertyMap deserialize(
     JsonElement json, Type typeOfT, JsonDeserializationContext context)
     throws JsonParseException {
   PropertyMap result = new PropertyMap();
   Iterator i$;
   Map.Entry<String, JsonElement> entry;
   if ((json instanceof JsonObject)) {
     JsonObject object = (JsonObject) json;
     for (i$ = object.entrySet().iterator(); i$.hasNext(); ) {
       entry = (Map.Entry) i$.next();
       if ((entry.getValue() instanceof JsonArray)) {
         for (JsonElement element : (JsonArray) entry.getValue()) {
           result.put(
               entry.getKey(), new Property((String) entry.getKey(), element.getAsString()));
         }
       }
     }
   } else if ((json instanceof JsonArray)) {
     for (JsonElement element : (JsonArray) json) {
       if ((element instanceof JsonObject)) {
         JsonObject object = (JsonObject) element;
         String name = object.getAsJsonPrimitive("name").getAsString();
         String value = object.getAsJsonPrimitive("value").getAsString();
         if (object.has("signature")) {
           result.put(
               name,
               new Property(name, value, object.getAsJsonPrimitive("signature").getAsString()));
         } else {
           result.put(name, new Property(name, value));
         }
       }
     }
   }
   return result;
 }
  private Map<String, List<String>> processSamplesGT(Map<String, String> options) {
    Map<String, List<String>> samplesGenotypes = new LinkedHashMap<>(10);
    List<String> genotypesList;

    String key, val;
    for (Map.Entry<String, String> entry : options.entrySet()) {
      key = entry.getKey();
      val = entry.getValue();

      if (key.startsWith("sampleGT_")) {
        String sampleName = key.replace("sampleGT_", "").replace("[]", "");
        String[] genotypes = val.split(",");

        if (samplesGenotypes.containsKey(sampleName)) {
          genotypesList = samplesGenotypes.get(sampleName);
        } else {

          genotypesList = new ArrayList<>();
          samplesGenotypes.put(sampleName, genotypesList);
        }

        for (int i = 0; i < genotypes.length; i++) {

          genotypesList.add(genotypes[i]);
        }
      }
    }
    return samplesGenotypes;
  }
Example #20
0
 public static void main(String[] args) {
   EnumMap<AlarmPoints, Command> em = new EnumMap<AlarmPoints, Command>(AlarmPoints.class);
   em.put(
       KITCHEN,
       new Command() {
         public void action() {
           print("Kitchen fire!");
         }
       });
   em.put(
       BATHROOM,
       new Command() {
         public void action() {
           print("Bathroom alert!");
         }
       });
   for (Map.Entry<AlarmPoints, Command> e : em.entrySet()) {
     printnb(e.getKey() + ": ");
     e.getValue().action();
   }
   try { // If there's no value for a particular key:
     em.get(UTILITY).action();
   } catch (Exception e) {
     print(e);
   }
 }
Example #21
0
  public Object sample(int n) {
    if ((n < 0) || (n >= size)) {
      throw new IllegalArgumentException(
          "Can't get element " + n + " from set " + this + " of size " + size);
    }

    if (n < individuals.size()) {
      return individuals.get(n);
    }

    int indexSoFar = individuals.size();
    for (Iterator iter = popAppSatisfiers.entrySet().iterator(); iter.hasNext(); ) {
      Map.Entry entry = (Map.Entry) iter.next();
      NumberVar popApp = (NumberVar) entry.getKey();
      ObjectSet satisfiers = (ObjectSet) entry.getValue();
      Set exceptions = (Set) popAppExceptions.get(popApp);

      int numInSet = satisfiers.size() - exceptions.size();
      if (n < indexSoFar + numInSet) {
        return sampleFromPOPApp(satisfiers, exceptions, n - indexSoFar);
      }
      indexSoFar += numInSet;
    }

    return null; // shouldn't get here
  }
Example #22
0
  private RequestHandler lookupHandler(String uri, String methodName) {
    // We don't normalize the URI here because it is normalized when
    // the HTTP request comes in.
    if (log.logDebug()) {
      log.debug("Look up handler for URI [" + uri + "] and method [" + methodName + "]");
    }

    RequestHandler handler = null;
    Map patternMap = (Map) this.uriHandlers.get(uri);
    if (patternMap == null) {
      if (log.logDebug()) {
        log.debug("Nothing registered for uri [" + uri + "]");
      }
      return null;
    }
    Iterator patterns = patternMap.entrySet().iterator();
    while (patterns.hasNext()) {
      Map.Entry entry = (Map.Entry) patterns.next();
      Pattern pattern = (Pattern) this.globalPatternMap.get(entry.getKey());
      if (pattern.matcher(methodName).find()) {
        if (log.logDebug()) {
          log.debug("Handler matched on pattern [" + pattern + "]");
        }
        handler = (RequestHandler) entry.getValue();
      }
    }
    return handler;
  }
  @Override
  public Long getUniqueDevicesSupportingBluetooth(
      Company company, Date eventDate, Campaign campaign, Device device) {
    String query =
        "SELECT COUNT(DISTINCT b.macAddress) FROM BluetoothSend b WHERE b.eventDate BETWEEN ?1 AND ?2 AND b.company = ?3 AND b.sendStatus in (1, 2, 3, 4, 5, 7) ";
    int paramCount = 3;
    HashMap<Integer, Object> params = new HashMap<Integer, Object>();
    if (campaign != null) {
      paramCount++;
      query += " AND b.campaign = ?" + paramCount + " ";
      params.put(paramCount, campaign);
    }
    if (device != null) {
      paramCount++;
      query += " AND b.device = ?" + paramCount + " ";
      params.put(paramCount, device);
    }
    Query q = em.createQuery(query);

    q.setParameter(1, eventDate);
    q.setParameter(2, DateUtil.getEndOfDay(eventDate));
    q.setParameter(3, company);

    for (Map.Entry<Integer, Object> entry : params.entrySet()) {
      Integer paramId = entry.getKey();
      Object object = entry.getValue();
      q.setParameter(paramId, object);
    }

    Long countResult = (Long) q.getSingleResult();
    return countResult;
  }
Example #24
0
  static void itTest4(Map s, int size, int pos) {
    IdentityHashMap seen = new IdentityHashMap(size);
    reallyAssert(s.size() == size);
    int sum = 0;
    timer.start("Iter XEntry            ", size);
    Iterator it = s.entrySet().iterator();
    Object k = null;
    Object v = null;
    for (int i = 0; i < size - pos; ++i) {
      Map.Entry x = (Map.Entry) (it.next());
      k = x.getKey();
      v = x.getValue();
      seen.put(k, k);
      if (x != MISSING) ++sum;
    }
    reallyAssert(s.containsKey(k));
    it.remove();
    reallyAssert(!s.containsKey(k));
    while (it.hasNext()) {
      Map.Entry x = (Map.Entry) (it.next());
      Object k2 = x.getKey();
      seen.put(k2, k2);
      if (x != MISSING) ++sum;
    }

    reallyAssert(s.size() == size - 1);
    s.put(k, v);
    reallyAssert(seen.size() == size);
    timer.finish();
    reallyAssert(sum == size);
    reallyAssert(s.size() == size);
  }
  @Override
  public Long getTotalContentDownloads(
      Company company, Date eventDate, Campaign campaign, Device device) {
    String query =
        "SELECT COUNT(b.id) FROM BluetoothSend b WHERE b.sendStatus = ?1 AND b.eventDate BETWEEN ?2 AND ?3 AND b.company = ?4 ";
    int paramCount = 4;
    HashMap<Integer, Object> params = new HashMap<Integer, Object>();
    if (campaign != null) {
      paramCount++;
      query += " AND b.campaign = ?" + paramCount + " ";
      params.put(paramCount, campaign);
    }
    if (device != null) {
      paramCount++;
      query += " AND b.device = ?" + paramCount + " ";
      params.put(paramCount, device);
    }

    Query q = em.createQuery(query);
    q.setParameter(1, BluetoothSend.STATUS_SENT);
    q.setParameter(2, eventDate);
    q.setParameter(3, DateUtil.getEndOfDay(eventDate));
    q.setParameter(4, company);

    for (Map.Entry<Integer, Object> entry : params.entrySet()) {
      Integer paramId = entry.getKey();
      Object object = entry.getValue();
      q.setParameter(paramId, object);
    }

    Long countResult = (Long) q.getSingleResult();
    return countResult;
  }
Example #26
0
 /** meters are not sampled. */
 public void mergeMeters(
     MetricInfo metricInfo,
     String meta,
     Map<Integer, MetricSnapshot> data,
     Map<String, Integer> metaCounters) {
   Map<Integer, MetricSnapshot> existing = metricInfo.get_metrics().get(meta);
   if (existing == null) {
     metricInfo.put_to_metrics(meta, data);
   } else {
     for (Map.Entry<Integer, MetricSnapshot> dataEntry : data.entrySet()) {
       Integer win = dataEntry.getKey();
       MetricSnapshot snapshot = dataEntry.getValue();
       MetricSnapshot old = existing.get(win);
       if (old == null) {
         existing.put(win, snapshot);
       } else {
         if (snapshot.get_ts() >= old.get_ts()) {
           old.set_ts(snapshot.get_ts());
           old.set_mean(old.get_mean() + snapshot.get_mean());
           old.set_m1(old.get_m1() + snapshot.get_m1());
           old.set_m5(old.get_m5() + snapshot.get_m5());
           old.set_m15(old.get_m15() + snapshot.get_m15());
         }
       }
     }
   }
   updateMetricCounters(meta, metaCounters);
 }
Example #27
0
 public static boolean isAcyclic(Digraph digraph) {
   int order = digraph.order();
   if (order == 0) return true;
   Set spanned = new HashSet(order);
   DepthFirstStampSearch dfs = new DepthFirstStampSearch(digraph, digraph.vertexIterator().next());
   for (Iterator i = digraph.vertexIterator(); i.hasNext(); ) {
     Object dfsRoot = i.next();
     if (spanned.contains(dfsRoot)) continue;
     dfs.reset(dfsRoot);
     Map dfsOrders = dfs.traverse(new HashMap(digraph.order()));
     for (Iterator j = dfsOrders.entrySet().iterator(); j.hasNext(); ) {
       Map.Entry entry = (Map.Entry) j.next();
       Object origin = entry.getKey();
       DepthFirstStampSearch.OrderPair orgOrders =
           (DepthFirstStampSearch.OrderPair) entry.getValue();
       spanned.add(origin);
       for (ArcIterator k = digraph.outgoingIterator(origin); k.hasNext(); ) {
         k.next();
         Object dst = k.getDestination();
         DepthFirstStampSearch.OrderPair dstOrders =
             (DepthFirstStampSearch.OrderPair) dfsOrders.get(dst);
         if (dstOrders.getPostOrder() > orgOrders.getPostOrder()) return false;
       }
     }
     if (dfsOrders.size() == order) break;
   }
   return true;
 }
    public boolean equals(Object o) {
      if (!(o instanceof Map.Entry)) return false;
      Map.Entry<?, ?> e = (Map.Entry<?, ?>) o;

      return (key == null ? e.getKey() == null : key.equals(e.getKey()))
          && (value == null ? e.getValue() == null : value.equals(e.getValue()));
    }
Example #29
0
 @Override
 public DfaInstructionState[] visitPush(
     PushInstruction instruction, DataFlowRunner runner, DfaMemoryState memState) {
   if (myContext == instruction.getPlace()) {
     final Map<DfaVariableValue, DfaVariableState> map =
         ((ValuableDataFlowRunner.MyDfaMemoryState) memState).getVariableStates();
     for (Map.Entry<DfaVariableValue, DfaVariableState> entry : map.entrySet()) {
       ValuableDataFlowRunner.ValuableDfaVariableState state =
           (ValuableDataFlowRunner.ValuableDfaVariableState) entry.getValue();
       DfaVariableValue variableValue = entry.getKey();
       final PsiExpression psiExpression = state.myExpression;
       if (psiExpression != null && variableValue.getQualifier() == null) {
         myValues.put(variableValue.getPsiVariable(), psiExpression);
       }
     }
     DfaValue value = instruction.getValue();
     if (value instanceof DfaVariableValue
         && ((DfaVariableValue) value).getQualifier() == null) {
       if (memState.isNotNull((DfaVariableValue) value)) {
         myNotNulls.add(((DfaVariableValue) value).getPsiVariable());
       }
       if (memState.isNull(value)) {
         myNulls.add(((DfaVariableValue) value).getPsiVariable());
       }
     }
   }
   return super.visitPush(instruction, runner, memState);
 }
Example #30
0
 public void mergeGauges(
     TopologyMetric tpMetric, MetaType metaType, String meta, Map<Integer, MetricSnapshot> data) {
   MetricInfo metricInfo = getMetricInfoByType(tpMetric, metaType);
   Map<Integer, MetricSnapshot> existing = metricInfo.get_metrics().get(meta);
   if (existing == null) {
     metricInfo.put_to_metrics(meta, data);
   } else {
     for (Map.Entry<Integer, MetricSnapshot> dataEntry : data.entrySet()) {
       Integer win = dataEntry.getKey();
       MetricSnapshot snapshot = dataEntry.getValue();
       MetricSnapshot old = existing.get(win);
       if (old == null) {
         existing.put(win, snapshot);
       } else {
         if (snapshot.get_ts() >= old.get_ts()) {
           old.set_ts(snapshot.get_ts());
           if (metaType != MetaType.TOPOLOGY) {
             old.set_doubleValue(snapshot.get_doubleValue());
           } else { // for topology metric, gauge might be add-able, e.g., cpu, memory, etc.
             old.set_doubleValue(old.get_doubleValue() + snapshot.get_doubleValue());
           }
         }
       }
     }
   }
 }