Ejemplo n.º 1
0
 private void loadBlocks() {
   Map<IBlockState, ModelResourceLocation> stateMap =
       blockModelShapes.getBlockStateMapper().putAllStateModelLocations();
   Collection<ModelResourceLocation> variants = Lists.newArrayList(stateMap.values());
   variants.add(
       new ModelResourceLocation(
           "minecraft:item_frame", "normal")); // Vanilla special cases item_frames so must we
   variants.add(new ModelResourceLocation("minecraft:item_frame", "map"));
   blockBar = ProgressManager.push("ModelLoader: blocks", variants.size());
   loadingBlockModels.addAll(variants);
   loadVariants(variants);
   ProgressManager.pop(blockBar);
 }
Ejemplo n.º 2
0
 /**
  * Store dependency tables for later retrieval by the EE.
  *
  * @param workunit
  */
 void trackNewWorkUnit(final Map<Integer, List<VoltTable>> dependencies) {
   for (final Entry<Integer, List<VoltTable>> e : dependencies.entrySet()) {
     // could do this optionally - debug only.
     verifyDependencySanity(e.getKey(), e.getValue());
     // create a new list of references to the workunit's table
     // to avoid any changes to the WorkUnit's list. But do not
     // copy the table data.
     final ArrayDeque<VoltTable> deque = new ArrayDeque<VoltTable>();
     deque.addAll(e.getValue());
     // intentionally overwrite the previous dependency id.
     // would a lookup and a clear() be faster?
     m_depsById.put(e.getKey(), deque);
   }
 }
Ejemplo n.º 3
0
  /**
   * Breadth-first search algorithm
   *
   * @param vehicle the considered vehicle
   * @param available the available tasks of the world
   * @param carried the tasks picked up and currently carried by the vehicle
   * @return a plan (list of actions)
   */
  public static Plan computeBFS(Vehicle vehicle, TaskSet available, TaskSet carried) {

    Plan plan = null;

    ArrayList<Task> availableTasks = new ArrayList<Task>(available);
    ArrayList<Task> carriedTasks = new ArrayList<Task>(carried);

    ArrayDeque<State> Q = new ArrayDeque<State>(); // States we will have to visit
    ArrayList<State> C = new ArrayList<State>(); // States we have already visited, prevent cycles

    City initialCity = vehicle.getCurrentCity();
    State initialState =
        new State(
            initialCity, availableTasks, carriedTasks, new ArrayList<Action>(), vehicle, 0, 0);

    Q.add(initialState);

    boolean foundFinalState = false;
    State finalState = null;

    while (!foundFinalState) {

      if (Q.isEmpty()) {
        foundFinalState = true;

      } else {
        State visitingState = Q.poll();

        if (visitingState.isFinal()) {
          finalState = visitingState;
          foundFinalState = true;
        } else if (!C.contains(visitingState)) {
          C.add(visitingState);
          Q.addAll(visitingState.next()); // Hopefully at the end of the list
        }
      }
    }

    if (finalState != null) {
      plan = new Plan(vehicle.getCurrentCity(), finalState.actionList);
    }

    return plan;
  }
Ejemplo n.º 4
0
 /**
  * Store dependency tables for later retrieval by the EE.
  *
  * @param workunit
  */
 void trackNewWorkUnit(final Map<Integer, List<VoltTable>> dependencies) {
   for (final Entry<Integer, List<VoltTable>> e : dependencies.entrySet()) {
     // could do this optionally - debug only.
     if (d) verifyDependencySanity(e.getKey(), e.getValue());
     // create a new list of references to the workunit's table
     // to avoid any changes to the WorkUnit's list. But do not
     // copy the table data.
     ArrayDeque<VoltTable> deque = m_depsById.get(e.getKey());
     if (deque == null) {
       deque = new ArrayDeque<VoltTable>();
       // intentionally overwrite the previous dependency id.
       // would a lookup and a clear() be faster?
       m_depsById.put(e.getKey(), deque);
     } else {
       deque.clear();
     }
     deque.addAll(e.getValue());
   }
   if (d) LOG.debug("Current InputDepencies:\n" + StringUtil.formatMaps(m_depsById));
 }
  private void processReferences(
      JsonSchemaObject root,
      Set<JsonSchemaObject> objects,
      @Nullable JsonSchemaExportedDefinitions definitions) {
    final ArrayDeque<JsonSchemaObject> queue = new ArrayDeque<>();
    queue.addAll(objects);
    int control = 10000;

    while (!queue.isEmpty()) {
      if (--control == 0) throw new RuntimeException("cyclic definitions search");

      final JsonSchemaObject current = queue.removeFirst();
      if ("#".equals(current.getRef())) continue;
      if (current.getRef() != null) {
        final JsonSchemaObject definition =
            findDefinition(myKey, current.getRef(), root, definitions);
        if (definition == null) {
          if (definitions == null) {
            // just skip current item
            current.setRef(null);
            continue;
          }
          throw new RuntimeException("Can not find definition: " + current.getRef());
        }
        if (definition.getRef() != null && !"#".equals(definition.getRef())) {
          queue.addFirst(current);
          queue.addFirst(definition);
          continue;
        }

        final JsonSchemaObject copy = new JsonSchemaObject();
        copy.setDefinitionAddress(current.getRef());
        copy.mergeValues(definition);
        copy.mergeValues(current);
        current.copyValues(copy);
        current.setRef(null);
      }
    }
  }
  @Override
  public final void run() {
    writeLock();
    try {
      _activeTasks.addAll(_queue);

      _queue.clear();
    } finally {
      writeUnlock();
    }

    for (T task; (task = _activeTasks.pollFirst()) != null; ) {
      final long begin = System.nanoTime();

      try {
        callTask(task);
      } catch (RuntimeException e) {
        _log.warn("", e);
      } finally {
        RunnableStatsManager.handleStats(
            task.getClass(), getCalledMethodName(), System.nanoTime() - begin);
      }
    }
  }
Ejemplo n.º 7
0
  /** Performs heuristic header substitution. */
  public IPath getPreferredRepresentativeHeaderByHeuristic(InclusionRequest request) {
    Set<IIndexFile> indexFiles = request.getDeclaringFiles().keySet();
    String symbolName = request.getBinding().getName();
    ArrayDeque<IIndexFile> front = new ArrayDeque<IIndexFile>();
    HashSet<IIndexFile> processed = new HashSet<IIndexFile>();

    try {
      // Look for headers without an extension and a matching name.
      if (fContext.isCXXLanguage()) {
        front.addAll(indexFiles);
        processed.addAll(indexFiles);

        while (!front.isEmpty()) {
          IIndexFile file = front.remove();

          String path = IncludeUtil.getPath(file);

          if (!hasExtension(path) && getFilename(path).equalsIgnoreCase(symbolName)) {
            // A C++ header without an extension and with a name which matches the name
            // of the symbol which should be declared is a perfect candidate for inclusion.
            return IndexLocationFactory.getAbsolutePath(file.getLocation());
          }

          // Process the next level of the include hierarchy.
          IIndexInclude[] includes = fContext.getIndex().findIncludedBy(file, 0);
          for (IIndexInclude include : includes) {
            IIndexFile includer = include.getIncludedBy();
            if (!processed.contains(includer)) {
              front.add(includer);
              processed.add(includer);
            }
          }
        }
      }

      // Repeat the process, this time only looking for headers without an extension.
      front.clear();
      front.addAll(indexFiles);
      processed.clear();
      processed.addAll(indexFiles);

      while (!front.isEmpty()) {
        IIndexFile file = front.remove();

        String path = IncludeUtil.getPath(file);

        if (fContext.isCXXLanguage() && !hasExtension(path)) {
          // A C++ header without an extension is still a very good candidate for inclusion.
          return IndexLocationFactory.getAbsolutePath(file.getLocation());
        }

        // Process the next level of the include hierarchy.
        IIndexInclude[] includes = fContext.getIndex().findIncludedBy(file, 0);
        for (IIndexInclude include : includes) {
          IIndexFile includer = include.getIncludedBy();
          if (!processed.contains(includer)) {
            URI uri = includer.getLocation().getURI();
            if (IncludeUtil.isSource(includer, fContext.getProject()) || isWorkspaceFile(uri)) {
              return IndexLocationFactory.getAbsolutePath(file.getLocation());
            }
            front.add(includer);
            processed.add(includer);
          }
        }
      }
    } catch (CoreException e) {
      CUIPlugin.log(e);
    }

    return request.getCandidatePaths().iterator().next();
  }
 private void refillWordQueue() {
   mWordQueue.clear();
   mWordQueue.addAll(Arrays.asList(mWordArray));
 }