You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AggregatingUDFFinder.java 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /* ====================================================================
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.ss.formula.udf;
  16. import org.apache.poi.ss.formula.functions.FreeRefFunction;
  17. import java.util.ArrayList;
  18. import java.util.Arrays;
  19. import java.util.Collection;
  20. /**
  21. * Collects add-in libraries and VB macro functions together into one UDF finder
  22. *
  23. * @author PUdalau
  24. */
  25. public class AggregatingUDFFinder implements UDFFinder {
  26. private final Collection<UDFFinder> _usedToolPacks;
  27. public AggregatingUDFFinder(UDFFinder ... usedToolPacks) {
  28. _usedToolPacks = new ArrayList<UDFFinder>(usedToolPacks.length);
  29. _usedToolPacks.addAll(Arrays.asList(usedToolPacks));
  30. }
  31. /**
  32. * Returns executor by specified name. Returns <code>null</code> if
  33. * function isn't contained by any registered tool pack.
  34. *
  35. * @param name Name of function.
  36. * @return Function executor. <code>null</code> if not found
  37. */
  38. public FreeRefFunction findFunction(String name) {
  39. FreeRefFunction evaluatorForFunction;
  40. for (UDFFinder pack : _usedToolPacks) {
  41. evaluatorForFunction = pack.findFunction(name);
  42. if (evaluatorForFunction != null) {
  43. return evaluatorForFunction;
  44. }
  45. }
  46. return null;
  47. }
  48. /**
  49. * Add a new toolpack
  50. *
  51. * @param toolPack the UDF toolpack to add
  52. */
  53. public void add(UDFFinder toolPack){
  54. _usedToolPacks.add(toolPack);
  55. }
  56. }