Exemple #1
0
 public synchronized void decreaseStock(Book book, int quantity, int jobSeqNum)
     throws InterruptedException {
   while (!inventory.containsKey(book) || inventory.get(book).intValue() < quantity) {
     wait();
   }
   inventory.put(book, inventory.get(book) - quantity);
   printWork(false, jobSeqNum, book, inventory.get(book) + quantity, inventory.get(book));
 }
Exemple #2
0
  @Override
  public TerminalSize getPreferredSize(List<Component> components) {
    EnumMap<Location, Component> layout = makeLookupMap(components);
    int preferredHeight =
        (layout.containsKey(Location.TOP)
                ? layout.get(Location.TOP).getPreferredSize().getRows()
                : 0)
            + Math.max(
                layout.containsKey(Location.LEFT)
                    ? layout.get(Location.LEFT).getPreferredSize().getRows()
                    : 0,
                Math.max(
                    layout.containsKey(Location.CENTER)
                        ? layout.get(Location.CENTER).getPreferredSize().getRows()
                        : 0,
                    layout.containsKey(Location.RIGHT)
                        ? layout.get(Location.RIGHT).getPreferredSize().getRows()
                        : 0))
            + (layout.containsKey(Location.BOTTOM)
                ? layout.get(Location.BOTTOM).getPreferredSize().getRows()
                : 0);

    int preferredWidth =
        Math.max(
            (layout.containsKey(Location.LEFT)
                    ? layout.get(Location.LEFT).getPreferredSize().getColumns()
                    : 0)
                + (layout.containsKey(Location.CENTER)
                    ? layout.get(Location.CENTER).getPreferredSize().getColumns()
                    : 0)
                + (layout.containsKey(Location.RIGHT)
                    ? layout.get(Location.RIGHT).getPreferredSize().getColumns()
                    : 0),
            Math.max(
                layout.containsKey(Location.TOP)
                    ? layout.get(Location.TOP).getPreferredSize().getColumns()
                    : 0,
                layout.containsKey(Location.BOTTOM)
                    ? layout.get(Location.BOTTOM).getPreferredSize().getColumns()
                    : 0));
    return new TerminalSize(preferredWidth, preferredHeight);
  }
  public void testEnumMap() throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    String JSON = "{ \"KEY1\" : \"\", \"WHATEVER\" : null }";

    // to get typing, must use type reference
    EnumMap<Key, String> result =
        mapper.readValue(JSON, new TypeReference<EnumMap<Key, String>>() {});

    assertNotNull(result);
    assertEquals(EnumMap.class, result.getClass());
    assertEquals(2, result.size());

    assertEquals("", result.get(Key.KEY1));
    // null should be ok too...
    assertTrue(result.containsKey(Key.WHATEVER));
    assertNull(result.get(Key.WHATEVER));

    // plus we have nothing for this key
    assertFalse(result.containsKey(Key.KEY2));
    assertNull(result.get(Key.KEY2));
  }
Exemple #4
0
 private EnumMap<Location, Component> makeLookupMap(List<Component> components) {
   EnumMap<Location, Component> map =
       new EnumMap<BorderLayout.Location, Component>(Location.class);
   List<Component> unassignedComponents = new ArrayList<Component>();
   for (Component component : components) {
     if (component.getLayoutData() instanceof Location) {
       map.put((Location) component.getLayoutData(), component);
     } else {
       unassignedComponents.add(component);
     }
   }
   // Try to assign components to available locations
   for (Component component : unassignedComponents) {
     for (Location location : AUTO_ASSIGN_ORDER) {
       if (!map.containsKey(location)) {
         map.put(location, component);
         break;
       }
     }
   }
   return map;
 }
Exemple #5
0
 private int intent(AbstractAction forAction) {
   return !KIDS.containsKey(forAction) ? -1 : KIDS.get(forAction).intent();
 }
Exemple #6
0
 public synchronized void increaseStock(Book book, int quantity, int jobSeqNum) {
   if (inventory.containsKey(book)) inventory.put(book, inventory.get(book) + quantity);
   else inventory.put(book, quantity);
   printWork(true, jobSeqNum, book, inventory.get(book) - quantity, inventory.get(book));
   notifyAll();
 }
Exemple #7
0
 boolean has(Field field) {
   return entries.containsKey(field);
 }
Exemple #8
0
  @Override
  public void doLayout(TerminalSize area, List<Component> components) {
    EnumMap<Location, Component> layout = makeLookupMap(components);
    int availableHorizontalSpace = area.getColumns();
    int availableVerticalSpace = area.getRows();

    // We'll need this later on
    int topComponentHeight = 0;
    int leftComponentWidth = 0;

    // First allocate the top
    if (layout.containsKey(Location.TOP)) {
      Component topComponent = layout.get(Location.TOP);
      topComponentHeight =
          Math.min(topComponent.getPreferredSize().getRows(), availableVerticalSpace);
      topComponent.setPosition(TerminalPosition.TOP_LEFT_CORNER);
      topComponent.setSize(new TerminalSize(availableHorizontalSpace, topComponentHeight));
      availableVerticalSpace -= topComponentHeight;
    }

    // Next allocate the bottom
    if (layout.containsKey(Location.BOTTOM)) {
      Component bottomComponent = layout.get(Location.BOTTOM);
      int bottomComponentHeight =
          Math.min(bottomComponent.getPreferredSize().getRows(), availableVerticalSpace);
      bottomComponent.setPosition(new TerminalPosition(0, area.getRows() - bottomComponentHeight));
      bottomComponent.setSize(new TerminalSize(availableHorizontalSpace, bottomComponentHeight));
      availableVerticalSpace -= bottomComponentHeight;
    }

    // Now divide the remaining space between LEFT, CENTER and RIGHT
    if (layout.containsKey(Location.LEFT)) {
      Component leftComponent = layout.get(Location.LEFT);
      leftComponentWidth =
          Math.min(leftComponent.getPreferredSize().getColumns(), availableHorizontalSpace);
      leftComponent.setPosition(new TerminalPosition(0, topComponentHeight));
      leftComponent.setSize(new TerminalSize(leftComponentWidth, availableVerticalSpace));
      availableHorizontalSpace -= leftComponentWidth;
    }
    if (layout.containsKey(Location.RIGHT)) {
      Component rightComponent = layout.get(Location.RIGHT);
      int rightComponentWidth =
          Math.min(rightComponent.getPreferredSize().getColumns(), availableHorizontalSpace);
      rightComponent.setPosition(
          new TerminalPosition(area.getColumns() - rightComponentWidth, topComponentHeight));
      rightComponent.setSize(new TerminalSize(rightComponentWidth, availableVerticalSpace));
      availableHorizontalSpace -= rightComponentWidth;
    }
    if (layout.containsKey(Location.CENTER)) {
      Component centerComponent = layout.get(Location.CENTER);
      centerComponent.setPosition(new TerminalPosition(leftComponentWidth, topComponentHeight));
      centerComponent.setSize(new TerminalSize(availableHorizontalSpace, availableVerticalSpace));
    }

    // Set the remaining components to 0x0
    for (Component component : components) {
      if (!layout.values().contains(component)) {
        component.setPosition(TerminalPosition.TOP_LEFT_CORNER);
        component.setSize(TerminalSize.ZERO);
      }
    }
  }
  private void readTechnique(Statement techStat) throws IOException {
    isUseNodes = false;
    String[] split = techStat.getLine().split(whitespacePattern);

    String name;
    if (split.length == 1) {
      name = TechniqueDef.DEFAULT_TECHNIQUE_NAME;
    } else if (split.length == 2) {
      name = split[1];
    } else {
      throw new IOException("Technique statement syntax incorrect");
    }

    String techniqueUniqueName = materialDef.getAssetName() + "@" + name;
    technique = new TechniqueDef(name, techniqueUniqueName.hashCode());

    for (Statement statement : techStat.getContents()) {
      readTechniqueStatement(statement);
    }

    technique.setShaderPrologue(createShaderPrologue(presetDefines));

    switch (technique.getLightMode()) {
      case Disable:
        technique.setLogic(new DefaultTechniqueDefLogic(technique));
        break;
      case MultiPass:
        technique.setLogic(new MultiPassLightingLogic(technique));
        break;
      case SinglePass:
        technique.setLogic(new SinglePassLightingLogic(technique));
        break;
      case StaticPass:
        technique.setLogic(new StaticPassLightingLogic(technique));
        break;
      case SinglePassAndImageBased:
        technique.setLogic(new SinglePassAndImageBasedLightingLogic(technique));
        break;
      default:
        throw new UnsupportedOperationException();
    }

    List<TechniqueDef> techniqueDefs = new ArrayList<>();

    if (isUseNodes) {
      nodesLoaderDelegate.computeConditions();

      // used for caching later, the shader here is not a file.

      // KIRILL 9/19/2015
      // Not sure if this is needed anymore, since shader caching
      // is now done by TechniqueDef.
      technique.setShaderFile(
          technique.hashCode() + "", technique.hashCode() + "", "GLSL100", "GLSL100");
      techniqueDefs.add(technique);
    } else if (shaderNames.containsKey(Shader.ShaderType.Vertex)
        && shaderNames.containsKey(Shader.ShaderType.Fragment)) {
      if (shaderLanguages.size() > 1) {
        for (int i = 1; i < shaderLanguages.size(); i++) {
          TechniqueDef td = null;
          try {
            td = (TechniqueDef) technique.clone();
          } catch (CloneNotSupportedException e) {
            e.printStackTrace();
          }
          td.setShaderFile(shaderNames, shaderLanguages.get(i));
          techniqueDefs.add(td);
        }
      }
      technique.setShaderFile(shaderNames, shaderLanguages.get(0));
      techniqueDefs.add(technique);

    } else {
      technique = null;
      shaderLanguages.clear();
      shaderNames.clear();
      presetDefines.clear();
      langSize = 0;
      logger.log(Level.WARNING, "Fixed function technique was ignored");
      logger.log(
          Level.WARNING,
          "Fixed function technique ''{0}'' was ignored for material {1}",
          new Object[] {name, key});
      return;
    }

    for (TechniqueDef techniqueDef : techniqueDefs) {
      materialDef.addTechniqueDef(techniqueDef);
    }

    technique = null;
    langSize = 0;
    shaderLanguages.clear();
    shaderNames.clear();
    presetDefines.clear();
  }