示例#1
1
 @Override
 default <U> Seq<U> scanRight(U zero, BiFunction<? super T, ? super U, ? extends U> operation) {
   Objects.requireNonNull(operation, "operation is null");
   return Collections.scanRight(
       this, zero, operation, List.empty(), List::prepend, Function.identity());
 }
 public Object getDefaultValue(Class<?> hint) {
   Object value;
   if (hint == null) {
     if (javaObject instanceof Boolean) {
       hint = ScriptRuntime.BooleanClass;
     }
   }
   if (hint == null || hint == ScriptRuntime.StringClass) {
     value = javaObject.toString();
   } else {
     String converterName;
     if (hint == ScriptRuntime.BooleanClass) {
       converterName = "booleanValue";
     } else if (hint == ScriptRuntime.NumberClass) {
       converterName = "doubleValue";
     } else {
       throw Context.reportRuntimeError0("msg.default.value");
     }
     Object converterObject = get(converterName, this);
     if (converterObject instanceof Function) {
       Function f = (Function) converterObject;
       value = f.call(Context.getContext(), f.getParentScope(), this, ScriptRuntime.emptyArgs);
     } else {
       if (hint == ScriptRuntime.NumberClass && javaObject instanceof Boolean) {
         boolean b = ((Boolean) javaObject).booleanValue();
         value = ScriptRuntime.wrapNumber(b ? 1.0 : 0.0);
       } else {
         value = javaObject.toString();
       }
     }
   }
   return value;
 }
示例#3
0
  /**
   * Utility method which dynamically binds a Context to the current thread, if none already exists.
   */
  public static Object callMethod(
      ContextFactory factory,
      final Scriptable thisObj,
      final Function f,
      final Object[] args,
      final long argsToWrap) {
    if (f == null) {
      // See comments in getFunction
      return Undefined.instance;
    }
    if (factory == null) {
      factory = ContextFactory.getGlobal();
    }

    final Scriptable scope = f.getParentScope();
    if (argsToWrap == 0) {
      return Context.call(factory, f, scope, thisObj, args);
    }

    Context cx = Context.getCurrentContext();
    if (cx != null) {
      return doCall(cx, scope, thisObj, f, args, argsToWrap);
    } else {
      return factory.call(
          new ContextAction() {
            public Object run(Context cx) {
              return doCall(cx, scope, thisObj, f, args, argsToWrap);
            }
          });
    }
  }
示例#4
0
 @Override
 protected boolean isCacheUseable(final Function<Class, EntityInfo> entityApplyer) {
   if (this.joinEntity == null) this.joinEntity = entityApplyer.apply(this.joinClass);
   if (!this.joinEntity.isCacheFullLoaded()) return false;
   if (this.nodes == null) return true;
   for (FilterNode node : this.nodes) {
     if (!node.isCacheUseable(entityApplyer)) return false;
   }
   return true;
 }
示例#5
0
 @Override
 protected <T> CharSequence createSQLJoin(
     final Function<Class, EntityInfo> func,
     final Map<Class, String> joinTabalis,
     final EntityInfo<T> info) {
   boolean morejoin = false;
   if (this.joinEntity == null) {
     if (this.joinClass != null) this.joinEntity = func.apply(this.joinClass);
     if (this.nodes != null) {
       for (FilterNode node : this.nodes) {
         if (node instanceof FilterJoinNode) {
           FilterJoinNode joinNode = ((FilterJoinNode) node);
           if (joinNode.joinClass != null) {
             joinNode.joinEntity = func.apply(joinNode.joinClass);
             if (this.joinClass != null && this.joinClass != joinNode.joinClass) morejoin = true;
           }
         }
       }
     }
   }
   StringBuilder sb = new StringBuilder();
   if (this.joinClass != null) {
     sb.append(createElementSQLJoin(joinTabalis, info, this));
   }
   if (morejoin) {
     Set<Class> set = new HashSet<>();
     if (this.joinClass != null) set.add(this.joinClass);
     for (FilterNode node : this.nodes) {
       if (node instanceof FilterJoinNode) {
         FilterJoinNode joinNode = ((FilterJoinNode) node);
         if (!set.contains(joinNode.joinClass)) {
           CharSequence cs = createElementSQLJoin(joinTabalis, info, joinNode);
           if (cs != null) {
             sb.append(cs);
             set.add(joinNode.joinClass);
           }
         }
       }
     }
   }
   return sb;
 }
示例#6
0
 private static Object doCall(
     Context cx,
     Scriptable scope,
     Scriptable thisObj,
     Function f,
     Object[] args,
     long argsToWrap) {
   // Wrap the rest of objects
   for (int i = 0; i != args.length; ++i) {
     if (0 != (argsToWrap & (1 << i))) {
       Object arg = args[i];
       if (!(arg instanceof Scriptable)) {
         args[i] = cx.getWrapFactory().wrap(cx, scope, arg, null);
       }
     }
   }
   return f.call(cx, scope, thisObj, args);
 }
 @Nullable
 public static <T> T processInputStream(
     @NotNull final VirtualFile file, @NotNull Function<InputStream, T> function) {
   InputStream stream = null;
   try {
     stream = file.getInputStream();
     return function.fun(stream);
   } catch (IOException e) {
     LOG.error(e);
   } finally {
     try {
       if (stream != null) {
         stream.close();
       }
     } catch (IOException e) {
       LOG.error(e);
     }
   }
   return null;
 }
  private static File getOldPath(
      final File oldInstallHome,
      final ConfigImportSettings settings,
      final String propertyName,
      final Function<String, String> fromPathSelector) {
    final File[] launchFileCandidates = getLaunchFilesCandidates(oldInstallHome, settings);

    // custom config folder
    for (File candidate : launchFileCandidates) {
      if (candidate.exists()) {
        String configDir =
            PathManager.substituteVars(
                getPropertyFromLaxFile(candidate, propertyName), oldInstallHome.getPath());
        if (configDir != null) {
          File probableConfig = new File(configDir);
          if (probableConfig.exists()) return probableConfig;
        }
      }
    }

    // custom config folder not found - use paths selector
    for (File candidate : launchFileCandidates) {
      if (candidate.exists()) {
        final String pathsSelector =
            getPropertyFromLaxFile(candidate, PathManager.PROPERTY_PATHS_SELECTOR);
        if (pathsSelector != null) {
          final String configDir = fromPathSelector.fun(pathsSelector);
          final File probableConfig = new File(configDir);
          if (probableConfig.exists()) {
            return probableConfig;
          }
        }
      }
    }

    return null;
  }
示例#9
0
 static <T, U> Node<U> apply(Node<T> node, Function<? super T, ? extends U> mapper) {
   final U value = mapper.apply(node.getValue());
   final List<Node<U>> children = node.getChildren().map(child -> Map.apply(child, mapper));
   return new Node<>(value, children);
 }
示例#10
0
文件: Function3.java 项目: phadej/uhc
 public Function3(Function prev, String nm) {
   this(prev.getName() + "." + nm);
 }