示例#1
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;
 }
示例#2
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);
 }
示例#3
0
 /**
  * parseLine calls the other parse methods to parse the given text.
  *
  * @param line
  */
 protected int parseLine(String line, TestElement el) {
   int count = 0;
   // we clean the line to get
   // rid of extra stuff
   String cleanedLine = this.cleanURL(line);
   log.debug("parsing line: " + line);
   // now we set request method
   el.setProperty(HTTPSamplerBase.METHOD, RMETHOD);
   if (FILTER != null) {
     log.debug("filter is not null");
     if (!FILTER.isFiltered(line, el)) {
       log.debug("line was not filtered");
       // increment the current count
       count++;
       // we filter the line first, before we try
       // to separate the URL into file and
       // parameters.
       line = FILTER.filter(cleanedLine);
       if (line != null) {
         createUrl(line, el);
       }
     } else {
       log.debug("Line was filtered");
     }
   } else {
     log.debug("filter was null");
     // increment the current count
     count++;
     // in the case when the filter is not set, we
     // parse all the lines
     createUrl(cleanedLine, el);
   }
   return count;
 }
 @VisibleForTesting
 void doClean(long projectId, List<Filter> filters, DbSession session) {
   List<PurgeableSnapshotDto> history = selectProjectSnapshots(projectId, session);
   for (Filter filter : filters) {
     filter.log();
     delete(filter.filter(history), session);
   }
 }
示例#5
0
  public void testControlled() {

    Filter filter = new EqualWidthFilter();

    double[] orig = {0.1, 3.4, 3.5, 3.6, 7.0, 9.0, 6.0, 4.4, 2.5, 3.9, 4.5, 2.8};

    filter.filter(orig);
  }
示例#6
0
 @Override
 public boolean filter(Object fo) {
   boolean rc = false;
   for (Filter f : flist) {
     rc = rc || f.filter(fo);
     if (rc) break;
   }
   return rc;
 }
示例#7
0
  public void testRandom() {

    Filter filter = new EqualWidthFilter();

    double[] orig = new double[21];

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

      orig[i] = Math.random() * 20;
    }

    filter.filter(orig);
  }
  public static Value filter_var(
      Env env, @ReadOnly Value value, @Optional Value filterIdV, @Optional Value flagV) {
    if (value.isArray()) {
      return BooleanValue.FALSE;
    }

    Filter filter = getFilter(env, filterIdV);

    if (filter == null) {
      return BooleanValue.FALSE;
    }

    return filter.filter(env, value, flagV);
  }
  public Value filter_input_array(
      Env env, int type, @Optional Value definition, @Optional("true") boolean isAddEmpty) {
    ArrayValue inputArray;

    switch (type) {
      case INPUT_POST:
        inputArray = env.getInputPostArray();
        break;
      case INPUT_GET:
        inputArray = env.getInputGetArray();
        break;
      case INPUT_COOKIE:
        inputArray = env.getInputCookieArray();
        break;
      case INPUT_ENV:
        inputArray = env.getInputEnvArray();
        break;
      default:
        return env.warning(L.l("filter input type is unknown: {0}", type));
    }

    Filter filter = getFilter(env, definition);

    ArrayValue array = new ArrayValueImpl();

    for (Map.Entry<Value, Value> entry : inputArray.entrySet()) {
      Value key = entry.getKey();
      Value value = entry.getValue();

      Value newKey = filter.filter(env, key, definition);
      Value newValue = filter.filter(env, value, definition);

      array.put(newKey, newValue);
    }

    return array;
  }
  private void handleArchive(File file) throws IOException {
    if (_logger.isDebugEnabled()) {
      _logger.debug("Scanning archive: " + file.getAbsolutePath());
    }

    ZipFile zip = new ZipFile(file);
    Enumeration<? extends ZipEntry> entries = zip.entries();

    while (entries.hasMoreElements()) {
      if (!_filter.continueScanning()) {
        break;
      }

      ZipEntry entry = entries.nextElement();
      String name = entry.getName();
      _filter.filter(name);
    }
  }
示例#11
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;
  }
  private void handleDirectory(File file, String path) {
    if (_logger.isDebugEnabled()) {
      _logger.debug("Scanning directory: " + file.getAbsolutePath());
    }

    for (File child : file.listFiles()) {
      if (!_filter.continueScanning()) {
        break;
      }

      String newPath = path == null ? child.getName() : path + '/' + child.getName();

      if (child.isDirectory()) {
        handleDirectory(child, newPath);
      } else {
        _filter.filter(newPath);
      }
    }
  }
示例#13
0
  public static void copyFileFiltering(
      @NotNull File from,
      @NotNull File to,
      boolean append,
      @NotNull String encoding,
      @NotNull List<Filter> filters,
      List<String> linesToInsert,
      List<String> linesToAppend)
      throws IOException {
    BufferedReader reader = null;
    PrintWriter writer = null;

    try {
      reader = new BufferedReader(new InputStreamReader(new FileInputStream(from), encoding));
      writer = new PrintWriter(new OutputStreamWriter(createOutputStream(to, append), encoding));

      for (String s : linesToInsert) {
        writer.println(s);
      }

      String line;

      while ((line = reader.readLine()) != null) {
        for (Filter filter : filters) {
          line = filter.filter(line);
        }

        writer.println(line);
      }

      for (String s : linesToAppend) {
        writer.println(s);
      }
    } finally {
      close(reader);
      close(writer);
    }
  }
  public static Value filter_input(
      Env env, int type, StringValue name, @Optional Value filterIdV, @Optional Value flagV) {
    ArrayValue array;

    switch (type) {
      case INPUT_POST:
        array = env.getInputPostArray();
        break;
      case INPUT_GET:
        array = env.getInputGetArray();
        break;
      case INPUT_COOKIE:
        array = env.getInputCookieArray();
        break;
      case INPUT_ENV:
        array = env.getInputEnvArray();
        break;
      default:
        return env.warning(L.l("filter input type is unknown: {0}", type));
    }

    Filter filter = getFilter(env, filterIdV);

    Value value = array.get(name);

    if (value == UnsetValue.UNSET) {
      int flags = AbstractFilter.getFlags(env, flagV);

      if ((flags & FILTER_NULL_ON_FAILURE) > 0) {
        return BooleanValue.FALSE;
      } else {
        return NullValue.NULL;
      }
    }

    return filter.filter(env, value, flagV);
  }
示例#15
0
  // **********************  PlugInTemplate Overrides  *************************//
  protected void processRequest(ChannelMap fwdData, PlugInChannelMap out) throws SAPIException {
    if (fwdData.NumberOfChannels() == 0) return;

    // Override member defaults with dynamic options:
    int minDecimation = this.minDecimation, maxSamples = this.maxSamples;
    boolean antiAlias = this.antiAlias;

    java.util.Properties opts = getRequestOptions();
    String temp;
    if ((temp = opts.getProperty("minDecimation")) != null) minDecimation = Integer.parseInt(temp);
    if ((temp = opts.getProperty("maxSamples")) != null) maxSamples = Integer.parseInt(temp);
    if ((temp = opts.getProperty("antiAlias")) != null) antiAlias = "true".equals(temp);

    // 2007/08/15  WHF  maxSamples applies to all channels:
    // 2007/08/15  WHF  Changed their mind.  Uncomment to re-enable.
    /*if (fwdData.NumberOfChannels() == 0) return;
    maxSamples /= fwdData.NumberOfChannels();
    if (maxSamples < 1) maxSamples = 1; */

    for (int index = 0; index < fwdData.NumberOfChannels(); ++index) {
      Object data;

      // Will add if necessary, otherwise just a lookup:
      int outIndex = out.Add(fwdData.GetName(index));

      // data = GetDataAsArray.get(fwdData, index);
      data = fwdData.GetDataAsArray(index);
      if (data == null) {
        System.err.println("ResamplePlugIn: Unsupported datatype.");
        continue;
      }

      int npts = Array.getLength(data);

      if (npts <= maxSamples && minDecimation < 2) {
        // length okay, just copy:
        out.PutTimeRef(fwdData, index);
        out.PutDataRef(outIndex, fwdData, index);
        continue;
      }

      // Calculate the decimation factor for this set:
      int ndeci = (int) Math.ceil(((double) npts) / maxSamples);
      if (ndeci < minDecimation) ndeci = minDecimation;

      double[] ddata = null;
      if (antiAlias) {
        if (fwdData.GetType(index) == ChannelMap.TYPE_FLOAT64) {
          ddata = (double[]) data;
        } else {
          ddata = new double[npts];
          for (int ii = 0; ii < npts; ++ii) ddata[ii] = Array.getDouble(data, ii);
        }
        double[] dataOut = new double[ddata.length];
        Filter lowPass = new Filter(1.0 / ndeci);
        lowPass.filter(ddata, dataOut);
        data = dataOut;
      }

      Object result = decimate(data, ndeci);
      out.PutTime(fwdData.GetTimeStart(index), fwdData.GetTimeDuration(index));
      if (antiAlias) {
        out.PutDataAsFloat64(outIndex, (double[]) result);
      } else {
        switch (fwdData.GetType(index)) {
          case ChannelMap.TYPE_FLOAT32:
            out.PutDataAsFloat32(outIndex, (float[]) result);
            break;

          case ChannelMap.TYPE_FLOAT64:
            out.PutDataAsFloat64(outIndex, (double[]) result);
            break;

          case ChannelMap.TYPE_INT16:
            out.PutDataAsInt16(outIndex, (short[]) result);
            break;

          case ChannelMap.TYPE_INT32:
            out.PutDataAsInt32(outIndex, (int[]) result);
            break;

          case ChannelMap.TYPE_INT64:
            out.PutDataAsInt64(outIndex, (long[]) result);
            break;

          case ChannelMap.TYPE_INT8:
            out.PutDataAsInt8(outIndex, (byte[]) result);
            break;
        }
      }
    }
  }