Exemplo n.º 1
0
  /**
   * Generate code corresponding to the given classes. The classes must have previously been
   * returned from {@link #enter}. If there are classes outstanding to be analyzed, that will be
   * done before any classes are generated. If null is specified, code will be generated for all
   * outstanding classes.
   *
   * @param classes a list of class elements
   */
  public Iterable<? extends JavaFileObject> generate(Iterable<? extends TypeElement> classes)
      throws IOException {
    final ListBuffer<JavaFileObject> results = new ListBuffer<JavaFileObject>();
    try {
      analyze(null); // ensure all classes have been parsed, entered, and analyzed

      if (classes == null) {
        compiler.generate(compiler.desugar(genList), results);
        genList.clear();
      } else {
        Filter f =
            new Filter() {
              public void process(Env<AttrContext> env) {
                compiler.generate(compiler.desugar(ListBuffer.of(env)), results);
              }
            };
        f.run(genList, classes);
      }
      if (genList.isEmpty()) {
        compiler.reportDeferredDiagnostics();
        cleanup();
      }
    } finally {
      if (compiler != null) compiler.log.flush();
    }
    return results;
  }
 public static void filtersToParameters(
     Collection<Filter> filters, List<String> parameters, Collection<VirtualFile> paths) {
   for (Filter filter : filters) {
     filter.getCommandParametersFilter().applyToCommandLine(parameters);
     filter.getCommandParametersFilter().applyToPaths(paths);
   }
 }
Exemplo n.º 3
0
  private DirFilter getDirFilter() {
    DirFilter deepestDirFilter = new DirFilter(Operator.EQ, preferences.get(Keys.MEDIA_DIR));
    for (Filter<? super Tables.Tracks> filter : getFilters()) {
      final DirFilter finalDeepestDirFilter = deepestDirFilter;
      deepestDirFilter =
          filter.accept(
              new TurtleFilterVisitor<Tables.Tracks, DirFilter>() {
                public DirFilter visit(DirFilter dirFilter) {
                  return finalDeepestDirFilter
                          .getValue()
                          .contains(dirFilter.getValueWithoutWildcards())
                      ? finalDeepestDirFilter
                      : new DirFilter(Operator.EQ, dirFilter.getValueWithoutWildcards());
                }

                public DirFilter visit(NotFilter<? super Tables.Tracks> notFilter) {
                  return finalDeepestDirFilter;
                }

                public <T, Z> DirFilter visit(
                    FieldFilter<? super Tables.Tracks, Z, T> fieldFilter) {
                  return finalDeepestDirFilter;
                }

                public DirFilter visit(FilterSet<? super Tables.Tracks> filterSet) {
                  return finalDeepestDirFilter;
                }
              });
    }
    return deepestDirFilter;
  }
  public static List<MemoryFilter> combineFilters(final Collection<Filter> filters) {
    final Merger[] mergers = {new UsersMerger()};
    if (filters.isEmpty()) return Collections.emptyList();

    final List<MemoryFilter> result = new ArrayList<MemoryFilter>();
    for (Filter filter : filters) {
      boolean taken = false;
      for (Merger combiner : mergers) {
        if (combiner.accept(filter.getMemoryFilter())) {
          taken = true;
          break;
        }
      }
      if (!taken) {
        result.add(filter.getMemoryFilter());
      }
    }
    for (Merger combiner : mergers) {
      final MemoryFilter combined = combiner.getResult();
      if (combined != null) {
        result.add(combined);
      }
    }
    return result;
  }
Exemplo n.º 5
0
 private Filter toFilter(List<String> filterList) {
   Filter filter = new Filter();
   if (filterList == null) return filter;
   for (String pattern : filterList) {
     filter.add(new IgnoredFiles(pattern));
   }
   return filter;
 }
Exemplo n.º 6
0
  /**
   * Main method for testing this class.
   *
   * @param argv should contain arguments to the filter: use -h for help
   */
  public static void main(String[] argv) {

    try {
      if (Utils.getFlag('b', argv)) {
        Filter.batchFilterFile(new AllFilter(), argv);
      } else {
        Filter.filterFile(new AllFilter(), argv);
      }
    } catch (Exception ex) {
      System.out.println(ex.getMessage());
    }
  }
Exemplo n.º 7
0
 public Filter createBaseFilter() {
   if (auxiliaryClasses.length == 0) {
     return Filter.createEqualityFilter("objectClass", structuralClass);
   } else {
     final ArrayList<Filter> comps = new ArrayList<Filter>(1 + auxiliaryClasses.length);
     comps.add(Filter.createEqualityFilter("objectClass", structuralClass));
     for (final String s : auxiliaryClasses) {
       comps.add(Filter.createEqualityFilter("objectClass", s));
     }
     return Filter.createANDFilter(comps);
   }
 }
Exemplo n.º 8
0
 /** Helper method for the above. */
 private <T> boolean setOrUnsetOrdering(
     final Class<T> category, final boolean set, final Filter service1, final Filter service2) {
   boolean done = false;
   T impl1 = null;
   T impl2 = null;
   for (final Iterator<? extends T> it = getServiceProviders(category, false); it.hasNext(); ) {
     final T factory = it.next();
     if (service1.filter(factory)) impl1 = factory;
     if (service2.filter(factory)) impl2 = factory;
     if (impl1 != null && impl2 != null && impl1 != impl2) {
       if (set) done |= setOrdering(category, impl1, impl2);
       else done |= unsetOrdering(category, impl1, impl2);
     }
   }
   return done;
 }
Exemplo n.º 9
0
 /**
  * Returns {@code true} is the specified {@code factory} meets the requirements specified by a map
  * of {@code hints} and the filter. This method is the entry point for the following public
  * methods:
  *
  * <ul>
  *   <li>Singleton {@link #getServiceProvider (Class category, Filter, Hints, Hints.Key)}
  *   <li>Iterator {@link #getServiceProviders(Class category, Filter, Hints)}
  * </ul>
  *
  * @param candidate The factory to checks.
  * @param category The factory category. Usually an interface.
  * @param hints The optional user requirements, or {@code null}.
  * @param filter The optional filter, or {@code null}.
  * @return {@code true} if the {@code factory} meets the user requirements.
  */
 final <T> boolean isAcceptable(
     final T candidate, final Class<T> category, final Hints hints, final Filter filter) {
   if (filter != null && !filter.filter(candidate)) {
     return false;
   }
   /*
    * Note: isAvailable(...) must be tested before checking the hints, because in current
    * Geotools implementation (especially DeferredAuthorityFactory), some hints computation
    * are deferred until a connection to the database is etablished (which 'isAvailable'
    * does in order to test the connection).
    */
   if (!isAvailable(candidate)) {
     return false;
   }
   if (hints != null) {
     if (candidate instanceof Factory) {
       if (!usesAcceptableHints((Factory) candidate, category, hints, (Set<Factory>) null)) {
         return false;
       }
     }
   }
   /*
    * Checks for optional user conditions supplied in FactoryRegistry subclasses.
    */
   return isAcceptable(candidate, category, hints);
 }
Exemplo n.º 10
0
  /**
   * Merges expensive descendant-or-self::node() steps.
   *
   * @param qc query context
   * @return original or new expression
   */
  private Expr mergeSteps(final QueryContext qc) {
    boolean opt = false;
    final int sl = steps.length;
    final ExprList stps = new ExprList(sl);
    for (int s = 0; s < sl; s++) {
      final Expr step = steps[s];
      // check for simple descendants-or-self step with succeeding step
      if (s < sl - 1 && step instanceof Step) {
        final Step curr = (Step) step;
        if (curr.simple(DESCORSELF, false)) {
          // check succeeding step
          final Expr next = steps[s + 1];
          // descendant-or-self::node()/child::X -> descendant::X
          if (simpleChild(next)) {
            ((Step) next).axis = DESC;
            opt = true;
            continue;
          }
          // descendant-or-self::node()/(X, Y) -> (descendant::X | descendant::Y)
          Expr e = mergeList(next);
          if (e != null) {
            steps[s + 1] = e;
            opt = true;
            continue;
          }
          // //(X, Y)[text()] -> (/descendant::X | /descendant::Y)[text()]
          if (next instanceof Filter && !next.has(Flag.FCS)) {
            final Filter f = (Filter) next;
            e = mergeList(f.root);
            if (e != null) {
              f.root = e;
              opt = true;
              continue;
            }
          }
        }
      }
      stps.add(step);
    }

    if (opt) {
      qc.compInfo(OPTDESC);
      return get(info, root, stps.finish());
    }
    return this;
  }
Exemplo n.º 11
0
 public Document processRecord(Document record, int position) throws Exception {
   for (HashMap<String, String> map : check_fields) {
     String fieldXpath = map.get("Field Name");
     String regexp = map.get("Field Value");
     Filter.apply(record, new OpDelete(), fieldXpath, new TextMatches(regexp));
   }
   return record;
 }
    public boolean include(Object object) {
      if (object instanceof IResource) {
        IResource resource = (IResource) object;
        IPath path =
            IResource.FILE == resource.getType()
                ? resource.getFullPath()
                : resource.getFullPath().addTrailingSeparator();
        object = path.toPortableString();
      }

      for (Iterator iter = filters.iterator(); iter.hasNext(); ) {
        Filter filter = (Filter) iter.next();
        if (filter.matches(object)) {
          return filter.inclusive();
        }
      }
      return default_;
    }
Exemplo n.º 13
0
 XmlNode[] getMatchingChildren(Filter filter) {
   ArrayList rv = new ArrayList();
   NodeList nodes = this.dom.getChildNodes();
   for (int i = 0; i < nodes.getLength(); i++) {
     Node node = nodes.item(i);
     if (filter.accept(node)) {
       rv.add(createImpl(node));
     }
   }
   return (XmlNode[]) rv.toArray(new XmlNode[0]);
 }
 @Override
 protected void doOKAction() {
   mySelectedClass = calcSelectedClass();
   if (mySelectedClass == null) return;
   if (!myClassFilter.isAccepted(mySelectedClass)) {
     Messages.showErrorDialog(
         myTabbedPane.getComponent(),
         SymbolPresentationUtil.getSymbolPresentableText(mySelectedClass) + " is not acceptable");
     return;
   }
   super.doOKAction();
 }
Exemplo n.º 15
0
 @Override
 public Set<String> retrieveUserGroups(LdapUserContext userContext) throws LdapException {
   Set<String> groups = new HashSet<String>();
   try {
     Filter groupClassFilter;
     if (groupObjectClass != null && !groupObjectClass.isEmpty()) {
       groupClassFilter = Filter.createEqualityFilter("objectClass", groupObjectClass);
     } else {
       groupClassFilter = Filter.createPresenceFilter("objectClass");
     }
     Filter filter =
         Filter.createANDFilter(
             groupClassFilter,
             Filter.createEqualityFilter(groupMemberAttribute, userContext.getDn()));
     LOGGER.debug(filter.toString());
     SearchResult searchResult =
         ldapConnectionPool.search(
             StringUtils.join(groupBase, ','), SearchScope.SUB, filter, "cn");
     for (SearchResultEntry entry : searchResult.getSearchEntries()) {
       groups.add(entry.getAttributeValue("cn"));
     }
     return groups;
   } catch (com.unboundid.ldap.sdk.LDAPException e) {
     throw new LdapException(e);
   }
 }
Exemplo n.º 16
0
  // This implementation requires that we open up privileges on JavaCompiler.
  // An alternative implementation would be to move this code to JavaCompiler and
  // wrap it here
  public Iterable<? extends Element> analyze(Iterable<? extends TypeElement> classes)
      throws IOException {
    enter(null); // ensure all classes have been entered

    final ListBuffer<Element> results = new ListBuffer<Element>();
    try {
      if (classes == null) {
        handleFlowResults(compiler.flow(compiler.attribute(compiler.todo)), results);
      } else {
        Filter f =
            new Filter() {
              public void process(Env<AttrContext> env) {
                handleFlowResults(compiler.flow(compiler.attribute(env)), results);
              }
            };
        f.run(compiler.todo, classes);
      }
    } finally {
      compiler.log.flush();
    }
    return results;
  }
Exemplo n.º 17
0
  public void init(final ServletContext servletContext, Injector injector) throws ServletException {
    // this may or may not be a singleton, but is only initialized once
    final Filter filter = injector.getInstance(filterKey);

    // initialize our filter with the configured context params and servlet context
    //noinspection OverlyComplexAnonymousInnerClass,AnonymousInnerClassWithTooManyMethods
    filter.init(
        new FilterConfig() {
          public String getFilterName() {
            return filterKey.toString();
          }

          public ServletContext getServletContext() {
            return servletContext;
          }

          public String getInitParameter(String s) {
            return initParams.get(s);
          }

          public Enumeration getInitParameterNames() {
            //noinspection InnerClassTooDeeplyNested,AnonymousInnerClassWithTooManyMethods
            return new Enumeration() {
              private final Iterator<String> paramNames = initParams.keySet().iterator();

              public boolean hasMoreElements() {
                return paramNames.hasNext();
              }

              public Object nextElement() {
                return paramNames.next();
              }
            };
          }
        });
  }
Exemplo n.º 18
0
 public Collection matches(Message message, NodeDescriptor senderID) {
   List matchingNeighbors = new ArrayList();
   // iterates over the subscribed neighbors
   Set keys = data.keySet();
   synchronized (data) {
     Iterator it = keys.iterator();
     NodeDescriptor currentNeighbor;
     while (it.hasNext()) {
       currentNeighbor = (NodeDescriptor) it.next();
       // Check if currentNeighbor is subscribed to the message
       // iterates over the set of filters for currentNeighbor
       if (senderID.equals(currentNeighbor)) continue;
       Iterator it1 = ((Collection) data.get(currentNeighbor)).iterator();
       while (it1.hasNext()) {
         Filter f = (Filter) it1.next();
         if (f.matches(message)) {
           matchingNeighbors.add(currentNeighbor);
           break;
         }
       }
     }
   }
   return matchingNeighbors;
 }
Exemplo n.º 19
0
  @Override
  public boolean hasNext() {

    canremove = false;

    if (nextObject != null) {
      return true;
    }

    while (iterator.hasNext()) {
      final Object obj = iterator.next();
      final T f = filter.filter(obj);
      if (f != null) {
        nextObject = f;
        return true;
      }
    }
    return false;
  }
Exemplo n.º 20
0
  @Test
  public void testSODA() {
    // should say fieldsTypes, maybe with object/component prefix
    Map<String, Object> eventTypes = new HashMap<>();
    eventTypes.put(LITERAL_SYMBOL, String.class);
    eventTypes.put(LITERAL_PRICE, Integer.class);

    EPStatementObjectModel model = new EPStatementObjectModel();
    model.setInsertInto(InsertIntoClause.create(LITERAL_RETURN_OBJ));
    model.setSelectClause(
        SelectClause.create().add(Expressions.avg(LITERAL_PRICE), LITERAL_AVG).add(LITERAL_PRICE));
    Filter filter = Filter.create("quotes_default", Expressions.eq(LITERAL_SYMBOL, "A"));
    model.setFromClause(
        FromClause.create(
            FilterStream.create(filter).addView("win", "length", Expressions.constant(2))));
    model.setHavingClause(
        Expressions.gt(Expressions.avg(LITERAL_PRICE), Expressions.constant(60.0)));

    TopologyBuilder builder = new TopologyBuilder();
    builder.setSpout(LITERAL_QUOTES, new RandomSentenceSpout());
    builder
        .setBolt(
            LITERAL_ESPER,
            (new EsperBolt())
                .addEventTypes(eventTypes)
                .addOutputTypes(
                    Collections.singletonMap(
                        LITERAL_RETURN_OBJ, Arrays.asList(LITERAL_AVG, LITERAL_PRICE)))
                .addObjectStatemens(Collections.singleton(model)))
        .shuffleGrouping(LITERAL_QUOTES);
    builder.setBolt("print", new PrinterBolt()).shuffleGrouping(LITERAL_ESPER, LITERAL_RETURN_OBJ);

    Config conf = new Config();
    LocalCluster cluster = new LocalCluster();
    cluster.submitTopology("test", conf, builder.createTopology());
    Utils.sleep(10000);
    cluster.shutdown();
    assertEquals(resultSODA.get(100), new Double(75.0));
    assertEquals(resultSODA.get(50), new Double(75.0));
  }
Exemplo n.º 21
0
 @Override
 public LdapUserContext findUser(String identityAttributeValue) throws LdapException {
   try {
     Filter userClassFilter;
     if (userObjectClass != null && !userObjectClass.isEmpty()) {
       userClassFilter = Filter.createEqualityFilter("objectClass", userObjectClass);
     } else {
       userClassFilter = Filter.createPresenceFilter("objectClass");
     }
     Filter filter =
         Filter.createANDFilter(
             userClassFilter,
             Filter.createEqualityFilter(userIdentityAttribute, identityAttributeValue));
     LOGGER.debug(filter.toString());
     String[] attributesToRetrieve;
     if (userAdditionalAttributes != null) {
       attributesToRetrieve = userAdditionalAttributes;
       if (!ArrayUtils.contains(attributesToRetrieve, "cn")
           || !ArrayUtils.contains(attributesToRetrieve, "CN")) {
         ArrayUtils.add(attributesToRetrieve, "cn");
       }
     } else {
       attributesToRetrieve = new String[] {"cn"};
     }
     SearchResult searchResult =
         ldapConnectionPool.search(
             StringUtils.join(userBase, ','), SearchScope.SUB, filter, attributesToRetrieve);
     if (searchResult.getEntryCount() != 1) {
       throw new UnknownAccountException();
     }
     SearchResultEntry searchResultEntry = searchResult.getSearchEntries().get(0);
     String dn = searchResultEntry.getDN();
     DefaultLdapUserContext ldapUserContext = internalCreateUser(dn);
     ldapUserContext.getKnownAttributes().put("cn", searchResultEntry.getAttributeValue("cn"));
     return ldapUserContext;
   } catch (com.unboundid.ldap.sdk.LDAPException e) {
     throw new LdapException(e);
   }
 }
Exemplo n.º 22
0
  private Filter createFilter(final T o, final AtomicBoolean addedRequiredOrAllowed)
      throws LDAPPersistException {
    final ArrayList<Attribute> attrs = new ArrayList<Attribute>(5);
    attrs.add(objectClassAttribute);

    for (final FieldInfo i : requiredFilterFields) {
      final Attribute a = i.encode(o, true);
      if (a == null) {
        throw new LDAPPersistException(
            ERR_OBJECT_HANDLER_FILTER_MISSING_REQUIRED_FIELD.get(i.getField().getName()));
      } else {
        attrs.add(a);
        addedRequiredOrAllowed.set(true);
      }
    }

    for (final GetterInfo i : requiredFilterGetters) {
      final Attribute a = i.encode(o);
      if (a == null) {
        throw new LDAPPersistException(
            ERR_OBJECT_HANDLER_FILTER_MISSING_REQUIRED_GETTER.get(i.getMethod().getName()));
      } else {
        attrs.add(a);
        addedRequiredOrAllowed.set(true);
      }
    }

    for (final FieldInfo i : alwaysAllowedFilterFields) {
      final Attribute a = i.encode(o, true);
      if (a != null) {
        attrs.add(a);
        addedRequiredOrAllowed.set(true);
      }
    }

    for (final GetterInfo i : alwaysAllowedFilterGetters) {
      final Attribute a = i.encode(o);
      if (a != null) {
        attrs.add(a);
        addedRequiredOrAllowed.set(true);
      }
    }

    for (final FieldInfo i : conditionallyAllowedFilterFields) {
      final Attribute a = i.encode(o, true);
      if (a != null) {
        attrs.add(a);
      }
    }

    for (final GetterInfo i : conditionallyAllowedFilterGetters) {
      final Attribute a = i.encode(o);
      if (a != null) {
        attrs.add(a);
      }
    }

    final ArrayList<Filter> comps = new ArrayList<Filter>(attrs.size());
    for (final Attribute a : attrs) {
      for (final ASN1OctetString v : a.getRawValues()) {
        comps.add(Filter.createEqualityFilter(a.getName(), v.getValue()));
      }
    }

    if (superclassHandler != null) {
      final Filter f = superclassHandler.createFilter(o, addedRequiredOrAllowed);
      if (f.getFilterType() == Filter.FILTER_TYPE_AND) {
        comps.addAll(Arrays.asList(f.getComponents()));
      } else {
        comps.add(f);
      }
    }

    return Filter.createANDFilter(comps);
  }
Exemplo n.º 23
0
 boolean filterIncludesItem(T graphObject) {
   return filter == null || filter.includeItem(graphObject);
 }
Exemplo n.º 24
0
  /** @throws Exception */
  private void loadWorkload() throws Exception {
    final boolean debug = LOG.isDebugEnabled();
    // Workload Trace
    if (this.params.containsKey(PARAM_WORKLOAD)) {
      assert (this.catalog_db != null) : "Missing catalog!";
      String path = new File(this.params.get(PARAM_WORKLOAD)).getAbsolutePath();

      boolean weightedTxns = this.getBooleanParam(PARAM_WORKLOAD_XACT_WEIGHTS, false);
      if (debug) LOG.debug("Use Transaction Weights in Limits: " + weightedTxns);

      // This will prune out duplicate trace records...
      if (params.containsKey(PARAM_WORKLOAD_REMOVE_DUPES)) {
        DuplicateTraceFilter filter = new DuplicateTraceFilter();
        this.workload_filter =
            (this.workload_filter != null ? filter.attach(this.workload_filter) : filter);
        if (debug) LOG.debug("Attached " + filter.debugImpl());
      }

      // TRANSACTION OFFSET
      if (params.containsKey(PARAM_WORKLOAD_XACT_OFFSET)) {
        this.workload_xact_offset = Long.parseLong(params.get(PARAM_WORKLOAD_XACT_OFFSET));
        ProcedureLimitFilter filter =
            new ProcedureLimitFilter(-1l, this.workload_xact_offset, weightedTxns);
        // Important! The offset should go in the front!
        this.workload_filter =
            (this.workload_filter != null ? filter.attach(this.workload_filter) : filter);
        if (debug) LOG.debug("Attached " + filter.debugImpl());
      }

      // BASE PARTITIONS
      if (params.containsKey(PARAM_WORKLOAD_RANDOM_PARTITIONS)
          || params.containsKey(PARAM_WORKLOAD_BASE_PARTITIONS)) {
        BasePartitionTxnFilter filter =
            new BasePartitionTxnFilter(new PartitionEstimator(catalog_db));

        // FIXED LIST
        if (params.containsKey(PARAM_WORKLOAD_BASE_PARTITIONS)) {
          for (String p_str : this.getParam(PARAM_WORKLOAD_BASE_PARTITIONS).split(",")) {
            workload_base_partitions.add(Integer.valueOf(p_str));
          } // FOR
          // RANDOM
        } else {
          double factor = this.getDoubleParam(PARAM_WORKLOAD_RANDOM_PARTITIONS);
          List<Integer> all_partitions =
              new ArrayList<Integer>(CatalogUtil.getAllPartitionIds(catalog_db));
          Collections.shuffle(all_partitions, new Random());
          workload_base_partitions.addAll(
              all_partitions.subList(0, (int) (all_partitions.size() * factor)));
        }
        filter.addPartitions(workload_base_partitions);
        this.workload_filter =
            (this.workload_filter != null ? this.workload_filter.attach(filter) : filter);
        if (debug) LOG.debug("Attached " + filter.debugImpl());
      }

      // Txn Limit
      this.workload_xact_limit = this.getLongParam(PARAM_WORKLOAD_XACT_LIMIT);
      Histogram<String> proc_histogram = null;

      // Include/exclude procedures from the traces
      if (params.containsKey(PARAM_WORKLOAD_PROC_INCLUDE)
          || params.containsKey(PARAM_WORKLOAD_PROC_EXCLUDE)) {
        Filter filter = new ProcedureNameFilter(weightedTxns);

        // INCLUDE
        String temp = params.get(PARAM_WORKLOAD_PROC_INCLUDE);
        if (temp != null && !temp.equals(ProcedureNameFilter.INCLUDE_ALL)) {

          // We can take the counts for PROC_INCLUDE and scale them
          // with the multiplier
          double multiplier = 1.0d;
          if (this.hasDoubleParam(PARAM_WORKLOAD_PROC_INCLUDE_MULTIPLIER)) {
            multiplier = this.getDoubleParam(PARAM_WORKLOAD_PROC_INCLUDE_MULTIPLIER);
            if (debug) LOG.debug("Workload Procedure Multiplier: " + multiplier);
          }

          // Default Txn Frequencies
          String procinclude = params.get(PARAM_WORKLOAD_PROC_INCLUDE);
          if (procinclude.equalsIgnoreCase("default")) {
            procinclude =
                AbstractProjectBuilder.getProjectBuilder(catalog_type)
                    .getTransactionFrequencyString();
          }

          Map<String, Integer> limits = new HashMap<String, Integer>();
          int total_unlimited = 0;
          int total = 0;
          for (String proc_name : procinclude.split(",")) {
            int limit = -1;
            // Check if there is a limit for this procedure
            if (proc_name.contains(":")) {
              String pieces[] = proc_name.split(":");
              proc_name = pieces[0];
              limit = (int) Math.round(Integer.parseInt(pieces[1]) * multiplier);
            }

            if (limit < 0) {
              if (proc_histogram == null) {
                if (debug) LOG.debug("Generating procedure histogram from workload file");
                proc_histogram = WorkloadUtil.getProcedureHistogram(new File(path));
              }
              limit = (int) proc_histogram.get(proc_name, 0);
              total_unlimited += limit;
            } else {
              total += limit;
            }
            limits.put(proc_name, limit);
          } // FOR
          // If we have a workload limit and some txns that we want
          // to get unlimited
          // records from, then we want to modify the other txns so
          // that we fill in the "gap"
          if (this.workload_xact_limit != null && total_unlimited > 0) {
            int remaining = this.workload_xact_limit.intValue() - total - total_unlimited;
            if (remaining > 0) {
              for (Entry<String, Integer> e : limits.entrySet()) {
                double ratio = e.getValue() / (double) total;
                e.setValue((int) Math.ceil(e.getValue() + (ratio * remaining)));
              } // FOR
            }
          }

          Histogram<String> proc_multiplier_histogram = null;
          if (debug) {
            if (proc_histogram != null) LOG.debug("Full Workload Histogram:\n" + proc_histogram);
            proc_multiplier_histogram = new Histogram<String>();
          }
          total = 0;
          for (Entry<String, Integer> e : limits.entrySet()) {
            if (debug) proc_multiplier_histogram.put(e.getKey(), e.getValue());
            ((ProcedureNameFilter) filter).include(e.getKey(), e.getValue());
            total += e.getValue();
          } // FOR
          if (debug)
            LOG.debug("Multiplier Histogram [total=" + total + "]:\n" + proc_multiplier_histogram);
        }

        // EXCLUDE
        temp = params.get(PARAM_WORKLOAD_PROC_EXCLUDE);
        if (temp != null) {
          for (String proc_name : params.get(PARAM_WORKLOAD_PROC_EXCLUDE).split(",")) {
            ((ProcedureNameFilter) filter).exclude(proc_name);
          } // FOR
        }

        // Sampling!!
        if (this.getBooleanParam(PARAM_WORKLOAD_PROC_SAMPLE, false)) {
          if (debug) LOG.debug("Attaching sampling filter");
          if (proc_histogram == null)
            proc_histogram = WorkloadUtil.getProcedureHistogram(new File(path));
          Map<String, Integer> proc_includes = ((ProcedureNameFilter) filter).getProcIncludes();
          SamplingFilter sampling_filter = new SamplingFilter(proc_includes, proc_histogram);
          filter = sampling_filter;
          if (debug) LOG.debug("Workload Procedure Histogram:\n" + proc_histogram);
        }

        // Attach our new filter to the chain (or make it the head if
        // it's the first one)
        this.workload_filter =
            (this.workload_filter != null ? this.workload_filter.attach(filter) : filter);
        if (debug) LOG.debug("Attached " + filter.debugImpl());
      }

      // TRANSACTION LIMIT
      if (this.workload_xact_limit != null) {
        ProcedureLimitFilter filter =
            new ProcedureLimitFilter(this.workload_xact_limit, weightedTxns);
        this.workload_filter =
            (this.workload_filter != null ? this.workload_filter.attach(filter) : filter);
        if (debug) LOG.debug("Attached " + filter.debugImpl());
      }

      // QUERY LIMIT
      if (params.containsKey(PARAM_WORKLOAD_QUERY_LIMIT)) {
        this.workload_query_limit = Long.parseLong(params.get(PARAM_WORKLOAD_QUERY_LIMIT));
        QueryLimitFilter filter = new QueryLimitFilter(this.workload_query_limit);
        this.workload_filter =
            (this.workload_filter != null ? this.workload_filter.attach(filter) : filter);
      }

      if (this.workload_filter != null && debug)
        LOG.debug("Workload Filters: " + this.workload_filter.toString());
      this.workload = new Workload(this.catalog);
      this.workload.load(path, this.catalog_db, this.workload_filter);
      this.workload_path = new File(path).getAbsolutePath();
      if (this.workload_filter != null) this.workload_filter.reset();
    }

    // Workload Statistics
    if (this.catalog_db != null) {
      this.stats = new WorkloadStatistics(this.catalog_db);
      if (this.params.containsKey(PARAM_STATS)) {
        String path = this.params.get(PARAM_STATS);
        if (debug) LOG.debug("Loading in workload statistics from '" + path + "'");
        this.stats_path = new File(path).getAbsolutePath();
        try {
          this.stats.load(path, this.catalog_db);
        } catch (Throwable ex) {
          throw new RuntimeException("Failed to load stats file '" + this.stats_path + "'", ex);
        }
      }

      // Scaling
      if (this.params.containsKey(PARAM_STATS_SCALE_FACTOR)) {
        double scale_factor = this.getDoubleParam(PARAM_STATS_SCALE_FACTOR);
        LOG.info("Scaling TableStatistics: " + scale_factor);
        AbstractTableStatisticsGenerator generator =
            AbstractTableStatisticsGenerator.factory(
                this.catalog_db, this.catalog_type, scale_factor);
        generator.apply(this.stats);
      }
    }
  }
Exemplo n.º 25
0
 public long getCardinality(Filter filter, BindingSet bindings) {
   long card = getCardinality(filter.getArg(), bindings);
   return (long) (card * 0.5);
 }
Exemplo n.º 26
0
/**
 * This frame shows an input record's XML in the form of a tree, with an added ability to copy the
 * values from any node for other purposes. There are controls to create selection criteria for
 * choosing particular records as the scan proceeds, and buttons for going to the first or the next
 * record.
 *
 * @author Gerald de Jong <*****@*****.**>
 */
public class InputFrame extends FrameBase {
  private static final DefaultTreeModel EMPTY_MODEL =
      new DefaultTreeModel(new DefaultMutableTreeNode("No input"));
  private JTree recordTree;
  private JComboBox filterBox = new JComboBox(Filter.values());
  private JTextField filterField = new JTextField();

  private enum Filter {
    REGEX("Regex"),
    MODULO("Modulo");

    private String name;

    private Filter(String name) {
      this.name = name;
    }

    @Override
    public String toString() {
      return name;
    }
  }

  public InputFrame(SipModel sipModel) {
    super(Which.INPUT, sipModel, "Input");
    sipModel.addParseListener(
        new SipModel.ParseListener() {
          @Override
          public void updatedRecord(MetadataRecord metadataRecord) {
            exec(new RecordSetter(metadataRecord));
          }
        });
    recordTree =
        new JTree(EMPTY_MODEL) {
          @Override
          public String getToolTipText(MouseEvent evt) {
            TreePath treePath = recordTree.getPathForLocation(evt.getX(), evt.getY());
            return treePath != null
                ? ((GroovyTreeNode) treePath.getLastPathComponent()).toolTip
                : "";
          }
        };
    recordTree.setToolTipText("Input Record");
    recordTree.setCellRenderer(new Renderer());
    recordTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    recordTree.setTransferHandler(new TreeTransferHandler());
    filterField.addActionListener(rewind);
  }

  @Override
  protected void buildContent(Container content) {
    content.add(scrollVH(recordTree), BorderLayout.CENTER);
    content.add(createRecordButtonPanel(), BorderLayout.SOUTH);
  }

  private JPanel createRecordButtonPanel() {
    JPanel p = new JPanel(new BorderLayout());
    p.setBorder(BorderFactory.createTitledBorder("Filter"));
    p.add(filterBox, BorderLayout.WEST);
    p.add(filterField, BorderLayout.CENTER);
    p.add(createButtonPanel(), BorderLayout.SOUTH);
    return p;
  }

  private JPanel createButtonPanel() {
    JPanel p = new JPanel(new GridLayout(1, 0));
    p.add(new JButton(rewind));
    p.add(new JButton(play));
    return p;
  }

  private class RecordSetter implements Swing {
    private MetadataRecord metadataRecord;

    private RecordSetter(MetadataRecord metadataRecord) {
      this.metadataRecord = metadataRecord;
    }

    @Override
    public void run() {
      if (metadataRecord == null) {
        recordTree.setModel(EMPTY_MODEL);
      } else {
        GroovyTreeNode root = new GroovyTreeNode(metadataRecord);
        recordTree.setModel(new DefaultTreeModel(root));
        root.expand();
      }
    }
  }

  private class GroovyTreeNode implements TreeNode, Comparable<GroovyTreeNode> {
    private static final int MAX_LENGTH = 40;
    private MetadataRecord metadataRecord;
    private GroovyTreeNode parent;
    private String attrKey, attrValue;
    private GroovyNode node;
    private Vector<GroovyTreeNode> children = new Vector<GroovyTreeNode>();
    private String string;
    private String toolTip;

    private GroovyTreeNode(MetadataRecord metadataRecord) {
      this(null, metadataRecord.getRootNode());
      this.metadataRecord = metadataRecord;
    }

    private GroovyTreeNode(GroovyTreeNode parent, String attrKey, String attrValue) {
      this.parent = parent;
      this.attrKey = attrKey;
      this.attrValue = attrValue;
      string = String.format("<html><b>%s</b> = %s</html>", attrKey, attrValue);
      toolTip = string; // todo
    }

    private GroovyTreeNode(GroovyTreeNode parent, GroovyNode node) {
      this.parent = parent;
      this.node = node;
      for (Map.Entry<String, String> entry : node.attributes().entrySet()) {
        children.add(new GroovyTreeNode(this, entry.getKey(), entry.getValue()));
      }
      if (node.getNodeValue() instanceof List) {
        string = node.getNodeName();
        toolTip = String.format("Size: %d", ((List) node.getNodeValue()).size());
      } else {
        String truncated = node.text();
        if (truncated.contains("\n") || truncated.length() >= MAX_LENGTH) {
          int index = truncated.indexOf('\n');
          if (index > 0) truncated = truncated.substring(0, index);
          if (truncated.length() >= MAX_LENGTH) truncated = truncated.substring(0, MAX_LENGTH);
          string = String.format("<html><b>%s</b> = %s ...</html>", node.getNodeName(), truncated);
          toolTip = tameTooltipText(node.text());
        } else {
          string = String.format("<html><b>%s</b> = %s</html>", node.getNodeName(), truncated);
          toolTip = truncated;
        }
      }
      if (this.node.getNodeValue() instanceof List) {
        for (Object sub : ((List) this.node.getNodeValue())) {
          GroovyNode subnode = (GroovyNode) sub;
          children.add(new GroovyTreeNode(this, subnode));
        }
        Collections.sort(children);
      }
    }

    @Override
    public TreeNode getChildAt(int i) {
      return children.elementAt(i);
    }

    @Override
    public int getChildCount() {
      return children.size();
    }

    @Override
    public TreeNode getParent() {
      return parent;
    }

    @Override
    public int getIndex(TreeNode treeNode) {
      return children.indexOf(treeNode);
    }

    @Override
    public boolean getAllowsChildren() {
      return !children.isEmpty();
    }

    @Override
    public boolean isLeaf() {
      return children.isEmpty();
    }

    @Override
    public Enumeration children() {
      return children.elements();
    }

    @Override
    public String toString() {
      return metadataRecord != null
          ? String.format("record %d", metadataRecord.getRecordNumber())
          : string;
    }

    public void expand() {
      if (!isLeaf()) {
        Timer timer =
            new Timer(
                50,
                new ActionListener() {
                  @Override
                  public void actionPerformed(ActionEvent e) {
                    recordTree.expandPath(getTreePath());
                    for (TreeNode sub : children) {
                      ((GroovyTreeNode) sub).expand();
                    }
                  }
                });
        timer.setRepeats(false);
        timer.start();
      }
    }

    public TreePath getTreePath() {
      List<TreeNode> list = new ArrayList<TreeNode>();
      compilePathList(list);
      return new TreePath(list.toArray());
    }

    private void compilePathList(List<TreeNode> list) {
      if (parent != null) parent.compilePathList(list);
      list.add(this);
    }

    private String tameTooltipText(String text) {
      List<String> lines = new ArrayList<String>();
      while (text.length() > MAX_LENGTH) {
        int pos = text.indexOf(' ', MAX_LENGTH - 10);
        if (pos < 0) break;
        if (pos > MAX_LENGTH + 5) pos = MAX_LENGTH;
        lines.add(text.substring(0, pos).trim());
        text = text.substring(pos).trim();
      }
      if (!text.trim().isEmpty()) lines.add(text);
      StringBuilder html = new StringBuilder("<html>");
      for (String line : lines) html.append(line).append("<br/>\n");
      return html.toString();
    }

    @Override
    public int compareTo(GroovyTreeNode gtn) {
      if (attrKey != null && gtn.attrKey == null) return -1;
      if (attrKey == null && gtn.attrKey != null) return 1;
      if (attrKey != null && gtn.attrKey != null) return attrKey.compareTo(gtn.attrKey);
      return node.getNodeName().compareTo(gtn.node.getNodeName());
    }
  }

  public static class Renderer extends DefaultTreeCellRenderer {

    @Override
    public Component getTreeCellRendererComponent(
        JTree tree,
        Object value,
        boolean sel,
        boolean expanded,
        boolean leaf,
        int row,
        boolean hasFocus) {
      Component component =
          super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
      if (value instanceof GroovyTreeNode) {
        GroovyTreeNode node = (GroovyTreeNode) value;
        if (node.attrKey != null) {
          setIcon(SwingHelper.ICON_ATTRIBUTE);
        } else if (!node.isLeaf()) {
          setIcon(SwingHelper.ICON_COMPOSITE);
        } else {
          setIcon(SwingHelper.ICON_VALUE);
        }
      } else {
        setIcon(SwingHelper.ICON_COMPOSITE);
      }
      return component;
    }
  }

  private RewindAction rewind = new RewindAction();

  private class RewindAction extends AbstractAction {
    private RewindAction() {
      super("First");
      putValue(Action.SMALL_ICON, SwingHelper.ICON_REWIND);
    }

    @Override
    public void actionPerformed(ActionEvent actionEvent) {
      sipModel.seekReset();
      play.actionPerformed(actionEvent);
    }
  }

  private PlayAction play = new PlayAction();

  private class PlayAction extends AbstractAction {
    private PlayAction() {
      super("Next");
      putValue(Action.SMALL_ICON, SwingHelper.ICON_PLAY);
    }

    @Override
    public void actionPerformed(ActionEvent actionEvent) {
      setEnabled(false);
      sipModel.seekRecord(
          createPredicate(),
          new Swing() {
            @Override
            public void run() {
              setEnabled(true);
            }
          });
    }
  }

  private SipModel.ScanPredicate createPredicate() {
    final String filterString = filterField.getText().trim();
    switch ((Filter) filterBox.getSelectedItem()) {
      case REGEX:
        return new SipModel.ScanPredicate() {
          @Override
          public boolean accept(MetadataRecord record) {
            return record.contains(Pattern.compile(filterString));
          }
        };
      case MODULO:
        int modulo;
        try {
          modulo = Integer.parseInt(filterString);
        } catch (NumberFormatException e) {
          modulo = 1;
        }
        if (modulo <= 0) modulo = 1;
        final int recordNumberModulo = modulo;
        return new SipModel.ScanPredicate() {
          @Override
          public boolean accept(MetadataRecord record) {
            return recordNumberModulo == 1 || record.getRecordNumber() % recordNumberModulo == 0;
          }
        };
      default:
        throw new RuntimeException();
    }
  }

  private static class TreeTransferHandler extends TransferHandler {

    protected Transferable createTransferable(JComponent c) {
      JTree tree = (JTree) c;
      TreePath[] paths = tree.getSelectionPaths();
      if (paths == null || paths.length != 1) return null;
      TreePath path = tree.getSelectionPath();
      GroovyTreeNode groovyTreeNode = (GroovyTreeNode) path.getLastPathComponent();
      return new StringTransferable((String) (groovyTreeNode.node.getNodeValue()));
    }

    public int getSourceActions(JComponent c) {
      return COPY;
    }
  }

  private static class StringTransferable implements Transferable {
    private String string;

    private static final DataFlavor[] flavors = {DataFlavor.stringFlavor};

    private StringTransferable(String string) {
      this.string = string;
    }

    @Override
    public DataFlavor[] getTransferDataFlavors() {
      return flavors;
    }

    @Override
    public boolean isDataFlavorSupported(DataFlavor flavor) {
      return flavor.equals(flavors[0]);
    }

    @Override
    public Object getTransferData(DataFlavor flavor)
        throws UnsupportedFlavorException, IOException {
      return string;
    }
  }
}
Exemplo n.º 27
0
  /**
   * Constructs an image information class based on the 5D image source, and the individual set of
   * pixels desired in that image. Needs Factory to query the database about statistics. (this might
   * not be a good thing)
   *
   * @param imageSource The image to store information about.
   * @param pixels The pixel source of the image.
   * @param dataSource The factory used to access the OME database. Is there a better way to do
   *     this?
   */
  public ImageInformation(Image imageSource, ImagePixels pixels, Factory dataSource) {
    this.imageSource = imageSource;
    this.pixels = pixels;
    this.pixelsAttribute = pixels.getPixelsAttribute();
    this.dataSource = dataSource;

    Map imageSourceMap = new HashMap();
    imageSourceMap.put("target", imageSource);

    // extract the channel/wavelength information for this image.
    List channelComponents = dataSource.findAttributes("PixelChannelComponent", imageSourceMap);

    final int pixelsID = pixelsAttribute.getID();

    // this taken straight out of the SVG viewer code
    // might be a faster/better/less OME-call-intensive way to do it
    channelComponents =
        Filter.grep(
            channelComponents,
            new GrepOperator() {
              public boolean eval(Object o) {
                Attribute attribute = (Attribute) o;
                Attribute pixels = attribute.getAttributeElement("Pixels");
                return pixels.getID() == pixelsID;
              }
            });

    channelInfo = new Wavelength[channelComponents.size()];
    for (int i = 0; i < channelComponents.size(); i++) {
      Attribute channel = (Attribute) channelComponents.get(i);
      channelInfo[i] = new Wavelength(channel.getIntElement("Index"));
    }

    CBS = ChannelBlackScaleData.getDefaultChannelScale(channelInfo);
    cbsMap = new HashMap();

    // hopefully this doesn't break right here

    // extract the proper stack statistics for this image,
    // this might be done the hard way (I dunno)

    Map moduleConstraints = new HashMap();
    moduleConstraints.put("name", "Fast Stack statistics");

    Module stackModule = (Module) dataSource.findObject("OME::Module", moduleConstraints);

    Map formalInputConstraints = new HashMap();
    formalInputConstraints.put("module_id", new Integer(stackModule.getID()));
    formalInputConstraints.put("name", "Pixels");

    Module.FormalInput formalInput =
        (Module.FormalInput)
            dataSource.findObject("OME::Module::FormalInput", formalInputConstraints);

    RemoteModuleExecution moduleExecution =
        (RemoteModuleExecution) pixelsAttribute.getModuleExecution();

    Map actualInputConstraints = new HashMap();
    actualInputConstraints.put("formal_input_id", new Integer(formalInput.getID()));
    actualInputConstraints.put("input_module_execution_id", new Integer(moduleExecution.getID()));

    ModuleExecution.ActualInput actualInput =
        (ModuleExecution.ActualInput)
            dataSource.findObject("OME::ModuleExecution::ActualInput", actualInputConstraints);

    final int stackAnalysisID = actualInput.getModuleExecution().getID();

    // retrieve statistics
    List stackMins = dataSource.findAttributes("StackMinimum", imageSourceMap);
    List stackMaxes = dataSource.findAttributes("StackMaximum", imageSourceMap);
    List stackMeans = dataSource.findAttributes("StackMean", imageSourceMap);
    List stackSigmas = dataSource.findAttributes("StackSigma", imageSourceMap);
    List stackGeomeans = dataSource.findAttributes("StackGeometricMean", imageSourceMap);
    List stackGeosigmas = dataSource.findAttributes("StackGeometricSigma", imageSourceMap);

    GrepOperator stackIDOperator =
        new GrepOperator() {
          public boolean eval(Object o) {
            Attribute attribute = (Attribute) o;
            RemoteModuleExecution execution =
                (RemoteModuleExecution) attribute.getModuleExecution();
            if (execution.getID() == stackAnalysisID) {
              return true;
            } else return false;
          }
        };

    List usableMins = Filter.grep(stackMins, stackIDOperator);
    List usableMaxes = Filter.grep(stackMaxes, stackIDOperator);
    List usableMeans = Filter.grep(stackMeans, stackIDOperator);
    List usableSigmas = Filter.grep(stackSigmas, stackIDOperator);
    List usableGeomeans = Filter.grep(stackGeomeans, stackIDOperator);
    List usableGeosigmas = Filter.grep(stackGeosigmas, stackIDOperator);

    sizeX = pixelsAttribute.getIntElement("SizeX");
    sizeY = pixelsAttribute.getIntElement("SizeY");
    sizeZ = pixelsAttribute.getIntElement("SizeZ");
    sizeC = pixelsAttribute.getIntElement("SizeC");
    sizeT = pixelsAttribute.getIntElement("SizeT");
    bitsPerPixel = pixelsAttribute.getIntElement("BitsPerPixel");

    stackStats = new StackStatistics[sizeC][sizeT];

    // initialize array
    for (int i = 0; i < sizeC; i++) {
      for (int j = 0; j < sizeT; j++) {
        stackStats[i][j] = new StackStatistics();
      }
    }

    // populate internal data structures
    for (Iterator iter = usableMins.iterator(); iter.hasNext(); ) {
      Attribute stackMin = (Attribute) iter.next();
      int theC = stackMin.getIntElement("TheC");
      int theT = stackMin.getIntElement("TheT");
      stackStats[theC][theT].setMin(stackMin.getIntElement("Minimum"));
    }

    for (Iterator iter = usableMaxes.iterator(); iter.hasNext(); ) {
      Attribute stackMax = (Attribute) iter.next();
      int theC = stackMax.getIntElement("TheC");
      int theT = stackMax.getIntElement("TheT");
      stackStats[theC][theT].setMax(stackMax.getIntElement("Maximum"));
    }

    for (Iterator iter = usableMeans.iterator(); iter.hasNext(); ) {
      Attribute stackMean = (Attribute) iter.next();
      int theC = stackMean.getIntElement("TheC");
      int theT = stackMean.getIntElement("TheT");
      stackStats[theC][theT].setMean(stackMean.getFloatElement("Mean"));
    }

    for (Iterator iter = usableSigmas.iterator(); iter.hasNext(); ) {
      Attribute stackSigma = (Attribute) iter.next();
      int theC = stackSigma.getIntElement("TheC");
      int theT = stackSigma.getIntElement("TheT");
      stackStats[theC][theT].setSigma(stackSigma.getFloatElement("Sigma"));
    }

    for (Iterator iter = usableGeomeans.iterator(); iter.hasNext(); ) {
      Attribute stackMean = (Attribute) iter.next();
      int theC = stackMean.getIntElement("TheC");
      int theT = stackMean.getIntElement("TheT");
      stackStats[theC][theT].setGeoMean(stackMean.getFloatElement("GeometricMean"));
    }

    for (Iterator iter = usableGeosigmas.iterator(); iter.hasNext(); ) {
      Attribute stackSigma = (Attribute) iter.next();
      int theC = stackSigma.getIntElement("TheC");
      int theT = stackSigma.getIntElement("TheT");
      stackStats[theC][theT].setGeoSigma(stackSigma.getFloatElement("GeometricSigma"));
    }
  }
Exemplo n.º 28
0
  public void destroy(Injector injector) {
    // may or may not be singleton, upto user to work out properly
    final Filter filter = injector.getInstance(filterKey);

    filter.destroy();
  }
Exemplo n.º 29
0
  /**
   * Sets the format of the input instances.
   *
   * @param instanceInfo an Instances object containing the input instance structure (any instances
   *     contained in the object are ignored - only the structure is required).
   * @return true if the outputFormat may be collected immediately
   */
  public boolean setInputFormat(Instances instanceInfo) throws Exception {

    super.setInputFormat(instanceInfo);
    setOutputFormat(instanceInfo);
    return true;
  }