// [databind#601]
 public void testEnumsWithJsonValueInMap() throws Exception {
   EnumMap<EnumWithJsonValue, String> input =
       new EnumMap<EnumWithJsonValue, String>(EnumWithJsonValue.class);
   input.put(EnumWithJsonValue.B, "x");
   assertEquals(
       "{\"" + EnumWithJsonValue.B.toString() + "\":\"x\"}", mapper.writeValueAsString(input));
 }
  /**
   * Set default levels for CopyNumberAlteration (AMP and HomDel) and Mutation (Mutated)
   *
   * @param theGeneticDataType
   */
  public void setDefault(GeneticDataTypes theGeneticDataType) {
    ResultDataTypeSpec theResultDataTypeSpec;

    switch (theGeneticDataType) {
      case CopyNumberAlteration:
        theResultDataTypeSpec = new ResultDataTypeSpec(GeneticDataTypes.CopyNumberAlteration);
        theResultDataTypeSpec.setTheDiscreteDataTypeSetSpec(
            new DiscreteDataTypeSetSpec(
                GeneticDataTypes.CopyNumberAlteration,
                GeneticTypeLevel.HomozygouslyDeleted,
                GeneticTypeLevel.Amplified));
        finalDataTypeSpecs.put(GeneticDataTypes.CopyNumberAlteration, theResultDataTypeSpec);
        break;

      case Expression:
        // TODO: s/b exception
        break;

      case Methylation:
        // TODO: s/b exception
        break;

      case Mutation:
        theResultDataTypeSpec = new ResultDataTypeSpec(GeneticDataTypes.Mutation);
        theResultDataTypeSpec.setTheDiscreteDataTypeSetSpec(
            new DiscreteDataTypeSetSpec(GeneticDataTypes.Mutation, GeneticTypeLevel.Mutated));
        finalDataTypeSpecs.put(GeneticDataTypes.Mutation, theResultDataTypeSpec);
        break;
    }
  }
示例#3
0
文件: Game.java 项目: jgacitua/PacMan
  /**
   * Returns an exact copy of the game. This may be used for forward searches such as minimax. The
   * copying is relatively efficient.
   *
   * @return the game
   */
  public Game copy() {
    Game copy = new Game();

    copy.seed = seed;
    copy.rnd = new Random(seed);
    copy.laberintoActua = laberintoActua;
    copy.pills = (BitSet) pills.clone();
    copy.powerPills = (BitSet) powerPills.clone();
    copy.indiceDeLaberinto = indiceDeLaberinto;
    copy.cuentaElLvl = cuentaElLvl;
    copy.tiempoLvlActual = tiempoLvlActual;
    copy.tiempoTotal = tiempoTotal;
    copy.score = score;
    copy.fastamasComerMultiplicador = fastamasComerMultiplicador;
    copy.juegoTerminado = juegoTerminado;
    copy.timeOfLastGlobalReversal = timeOfLastGlobalReversal;
    copy.pacmanFueComido = pacmanFueComido;
    copy.pastillaFueComida = pastillaFueComida;
    copy.pildoraPoderFueComida = pildoraPoderFueComida;
    copy.pacman = pacman.copy();

    copy.fantasmaComido = new EnumMap<GHOST, Boolean>(GHOST.class);
    copy.fantasmas = new EnumMap<GHOST, Ghost>(GHOST.class);

    for (GHOST ghostType : GHOST.values()) {
      copy.fantasmas.put(ghostType, fantasmas.get(ghostType).copy());
      copy.fantasmaComido.put(ghostType, fantasmaComido.get(ghostType));
    }

    return copy;
  }
示例#4
0
 public void actionPerformed(java.awt.event.ActionEvent e) {
   for (Con con : reflectivities.keySet()) {
     int idx = reflectivities.get(con);
     if (dlg.panelMain.mark != null && (idx == reflBox.getSelectedIndex()))
       dlg.panelMain.mark.setRefl(con);
   }
 }
 /**
  * satisfy for continuous data types.
  *
  * @param theGeneticDataType
  * @return true if the value is in one of the inequalities passed by the spec
  */
 public boolean satisfy(GeneticDataTypes theGeneticDataType, float value)
     throws IllegalArgumentException {
   if (theGeneticDataType.getTheDataTypeCategory().equals(DataTypeCategory.Discrete)) {
     throw new IllegalArgumentException(
         "satisfy for continuous data types only takes continuous GeneticDataTypes");
   }
   ResultDataTypeSpec theResultDataTypeSpec = finalDataTypeSpecs.get(theGeneticDataType);
   if (null == theResultDataTypeSpec) {
     return false;
   }
   if (theResultDataTypeSpec.acceptAll) {
     return true;
   }
   if (theResultDataTypeSpec.combinedLesserContinuousDataTypeSpec != null
       && finalDataTypeSpecs
           .get(theGeneticDataType)
           .combinedLesserContinuousDataTypeSpec
           .satisfy(value)) {
     return true;
   }
   if (theResultDataTypeSpec.combinedGreaterContinuousDataTypeSpec != null
       && finalDataTypeSpecs
           .get(theGeneticDataType)
           .combinedGreaterContinuousDataTypeSpec
           .satisfy(value)) {
     return true;
   }
   return false;
 }
示例#6
0
 public Strategy strategyFor(CircleDimension dimension) {
   if (strategies.containsKey(dimension)) {
     return strategies.get(dimension);
   } else {
     return dimension.defaultStrategy();
   }
 }
示例#7
0
 public void actionPerformed(java.awt.event.ActionEvent e) {
   for (Sts sts : statuses.keySet()) {
     int idx = statuses.get(sts);
     if (dlg.panelMain.mark != null && (idx == statusBox.getSelectedIndex()))
       dlg.panelMain.mark.setStatus(sts);
   }
 }
示例#8
0
  public void calcPlanetaryPosition(Set<Planet> planets) {

    planetPos = new EnumMap<Planet, Double>(Planet.class);

    isReverse = new EnumMap<Planet, Boolean>(Planet.class);

    double[] res = new double[6];
    StringBuffer sbErr = new StringBuffer();

    for (Planet planet : planets) {

      int rc =
          sw.swe_calc_ut(sweDate.getJulDay(), planet.planetNo(), AstroConsts.iflag, res, sbErr);
      planetPos.put(planet, res[0]);

      if ((res[3] < 0) && (!Planet.isNode(planet))) {

        isReverse.put(planet, true);
      }
    }

    // No-way to compute ketu pos from swisseph
    Double rahuPos = planetPos.get(Planet.Rahu);

    if (rahuPos != null) {
      double ketuPos = (rahuPos + 180.00) % 360;
      planetPos.put(Planet.Ketu, ketuPos);
    }
    // System.out.println(sbErr);
  }
示例#9
0
 public void sendToAllClients(MSPacket packet, World world, int x, int y, int z, int maxDistance) {
   channels
       .get(Side.SERVER)
       .attr(FMLOutboundHandler.FML_MESSAGETARGET)
       .set(FMLOutboundHandler.OutboundTarget.ALL);
   channels.get(Side.SERVER).writeOutbound(packet);
 }
示例#10
0
 public void actionPerformed(java.awt.event.ActionEvent e) {
   if ((dlg.panelMain.mark.getObject() != Obj.MORFAC)
       || (dlg.panelMain.mark.getCategory() == Cat.MOR_BUOY)) {
     for (Shp shp : shapes.keySet()) {
       JRadioButton button = shapes.get(shp);
       if (button.isSelected()) {
         dlg.panelMain.mark.setShape(shp);
         if (SeaMark.EntMAP.get(dlg.panelMain.mark.getObject()) != Ent.MOORING) {
           dlg.panelMain.mark.setObject(objects.get(shp));
           if (dlg.panelMain.mark.getObjColour(0) == Col.UNKCOL) {
             dlg.panelMain.mark.setObjPattern(Pat.NOPAT);
             dlg.panelMain.mark.setObjColour(Col.YELLOW);
           }
           if (button == cairnButton) {
             dlg.panelMain.mark.setObjPattern(Pat.NOPAT);
             dlg.panelMain.mark.setObjColour(Col.UNKCOL);
           }
           topmarkButton.setVisible(dlg.panelMain.mark.testValid());
         }
         button.setBorderPainted(true);
       } else button.setBorderPainted(false);
     }
     dlg.panelMain.panelMore.syncPanel();
   }
 }
示例#11
0
 public void lower(ArrayCopySlowPathNode arraycopy, LoweringTool tool) {
   StructuredGraph graph = arraycopy.graph();
   if (!graph.getGuardsStage().areFrameStatesAtDeopts()) {
     // Can't be lowered yet
     return;
   }
   SnippetInfo snippetInfo = arraycopy.getSnippet();
   Arguments args = new Arguments(snippetInfo, graph.getGuardsStage(), tool.getLoweringStage());
   args.add("nonNullSrc", arraycopy.getSource());
   args.add("srcPos", arraycopy.getSourcePosition());
   args.add("nonNullDest", arraycopy.getDestination());
   args.add("destPos", arraycopy.getDestinationPosition());
   if (snippetInfo == arraycopyUnrolledWorkSnippet) {
     args.addConst("length", ((Integer) arraycopy.getArgument()).intValue());
     args.addConst("elementKind", arraycopy.getElementKind());
   } else {
     args.add("length", arraycopy.getLength());
   }
   if (snippetInfo == arraycopyPredictedObjectWorkSnippet) {
     HotSpotResolvedObjectType arrayKlass =
         (HotSpotResolvedObjectType) tool.getMetaAccess().lookupJavaType(Object[].class);
     ValueNode objectArrayKlass =
         ConstantNode.forConstant(
             KlassPointerStamp.klassNonNull(),
             arrayKlass.klass(),
             tool.getMetaAccess(),
             arraycopy.graph());
     args.add("objectArrayKlass", objectArrayKlass);
     args.addConst("counter", arraycopyCallCounters.get(JavaKind.Object));
     args.addConst("copiedCounter", arraycopyCallCopiedCounters.get(JavaKind.Object));
   }
   instantiate(args, arraycopy);
 }
示例#12
0
 public void actionPerformed(java.awt.event.ActionEvent e) {
   for (Cat cat : categories.keySet()) {
     int idx = categories.get(cat);
     if (dlg.node != null && (idx == categoryBox.getSelectedIndex()))
       dlg.panelMain.mark.setCategory(cat);
   }
 }
示例#13
0
  private void targetStateChanged(
      final ConsumerTarget.State oldState, final ConsumerTarget.State newState) {
    if (oldState != newState) {
      if (newState == ConsumerTarget.State.CLOSED) {
        if (_targetClosed.compareAndSet(false, true)) {
          getEventLogger().message(getLogSubject(), SubscriptionMessages.CLOSE());
        }
      }

      if (newState == ConsumerTarget.State.SUSPENDED) {
        _suspendedConsumerLoggingTicker.setStartTime(System.currentTimeMillis());
        getSessionModel().addTicker(_suspendedConsumerLoggingTicker);
      } else {
        getSessionModel().removeTicker(_suspendedConsumerLoggingTicker);
      }
    }

    if (newState == ConsumerTarget.State.CLOSED && oldState != newState && !_closed.get()) {
      closeAsync();
    }
    final StateChangeListener<? super QueueConsumerImpl, State> stateListener = getStateListener();
    if (stateListener != null) {
      stateListener.stateChanged(this, STATE_MAP.get(oldState), STATE_MAP.get(newState));
    }
  }
 // [JACKSON-212]
 public void testToStringEnumWithEnumMap() throws Exception {
   ObjectMapper m = new ObjectMapper();
   m.configure(SerializationFeature.WRITE_ENUMS_USING_TO_STRING, true);
   EnumMap<LowerCaseEnum, String> enums = new EnumMap<LowerCaseEnum, String>(LowerCaseEnum.class);
   enums.put(LowerCaseEnum.C, "value");
   assertEquals("{\"c\":\"value\"}", m.writeValueAsString(enums));
 }
 public static final void sendToServer(BasePacket packet) {
   channels
       .get(Side.CLIENT)
       .attr(FMLOutboundHandler.FML_MESSAGETARGET)
       .set(FMLOutboundHandler.OutboundTarget.TOSERVER);
   channels.get(Side.CLIENT).writeOutbound(packet);
 }
  /** Returns the Information of a ParsedPage which are selected by the actual configuration */
  public String getSelectedText(ParsedPage pp) {
    if (pp == null) return null;

    StringBuilder sb = new StringBuilder();

    levelModifier = pp.getSection(0).getLevel() - 1;

    if (pageHandling == null) {
      if (firstParagraphHandling != null) {
        handleContent(pp.getFirstParagraph(), firstParagraphHandling, sb);
        deleteParagraph(pp.getFirstParagraphNr(), pp.getSections());
      }
      for (Section s : pp.getSections()) handleSection(s, sb);
    } else {
      if (pageHandling.get(CIT.TEXT)) {
        sb.append(pp.getText());
      } else {
        if (pageHandling.get(CIT.BOLD)) {
          handleSpans(pp.getFormatSpans(FormatType.BOLD), pp.getText(), sb);
        }
        if (pageHandling.get(CIT.ITALIC)) {
          handleSpans(pp.getFormatSpans(FormatType.ITALIC), pp.getText(), sb);
        }
      }

      if (pageHandling.get(CIT.LINK)) handleLinks(pp.getLinks(), !pageHandling.get(CIT.TEXT), sb);
    }

    return sb.toString().trim();
  }
 public static final void sendToAll(BasePacket packet) {
   channels
       .get(Side.SERVER)
       .attr(FMLOutboundHandler.FML_MESSAGETARGET)
       .set(FMLOutboundHandler.OutboundTarget.ALL);
   channels.get(Side.SERVER).writeOutbound(packet);
 }
 public static void main(String[] args) {
   // 创建EnumMap对象,该EnumMap的所有key都是Season枚举类的枚举值
   EnumMap enumMap = new EnumMap(Season.class);
   enumMap.put(Season.SUMMER, "夏日炎炎");
   enumMap.put(Season.SPRING, "春暖花开");
   System.out.println(enumMap);
 }
示例#19
0
 protected void addCount(ResultType type) throws CouldNotReceiveResultException {
   if (!resultCounts.containsKey(type)) {
     resultCounts.put(type, 1);
   } else {
     resultCounts.put(type, resultCounts.get(type) + 1);
   }
 }
  public static boolean isValid(EnumMap<?, ?> expected, EnumMap<?, ?> map) {
    if (map == null) {
      return false;
    }

    Set<?> entries = expected.entrySet();
    Iterator<?> entryIter = entries.iterator();
    while (entryIter.hasNext()) {
      Entry<?, ?> entry = (Entry<?, ?>) entryIter.next();

      Object value = map.get(entry.getKey());

      if (value != entry.getValue()) {
        if (value == null || entry.getValue() == null) {
          return false;
        }

        if (!map.get(entry.getKey()).equals(entry.getValue())) {
          return false;
        }
      }
    }

    return true;
  }
示例#21
0
 public void actionPerformed(java.awt.event.ActionEvent e) {
   for (Cns cns : constructions.keySet()) {
     int idx = constructions.get(cns);
     if (dlg.panelMain.mark != null && (idx == constrBox.getSelectedIndex()))
       dlg.panelMain.mark.setConstr(cns);
   }
 }
示例#22
0
  protected void registerTokens(final EnumMap<RTerminal, IToken> map) {
    map.put(RTerminal.EOF, Token.EOF);

    putAll(map, IRTextTokens.FLOWCONTROL, getToken(IRTextTokens.FLOWCONTROL_KEY));
    putAll(map, IRTextTokens.GROUPING, getToken(IRTextTokens.GROUPING_KEY));
    putAll(map, IRTextTokens.SEPARATOR, getToken(IRTextTokens.SEPARATOR_KEY));
    putAll(map, IRTextTokens.ASSIGN, getToken(IRTextTokens.ASSIGN_KEY));
    putAll(map, IRTextTokens.ASSIGN_SUB_EQUAL, getToken(IRTextTokens.ASSIGN_SUB_EQUAL_KEY));
    putAll(map, IRTextTokens.OP, getToken(IRTextTokens.OP_KEY));
    putAll(map, IRTextTokens.OP_SUB_LOGICAL, getToken(IRTextTokens.OP_SUB_LOGICAL_KEY));
    putAll(map, IRTextTokens.OP_SUB_RELATIONAL, getToken(IRTextTokens.OP_SUB_RELATIONAL_KEY));
    putAll(map, IRTextTokens.SUBACCESS, getToken(IRTextTokens.SUBACCESS_KEY));
    putAll(map, IRTextTokens.NSGET, getToken(IRTextTokens.SUBACCESS_KEY));

    putAll(map, IRTextTokens.SPECIALCONST, getToken(IRTextTokens.SPECIALCONST_KEY));
    putAll(map, IRTextTokens.LOGICALCONST, getToken(IRTextTokens.LOGICALCONST_KEY));
    putAll(map, IRTextTokens.SYMBOL, getToken(IRTextTokens.SYMBOL_KEY));

    putAll(map, IRTextTokens.NUM, getToken(IRTextTokens.NUM_KEY));
    putAll(map, IRTextTokens.NUM_SUB_INT, getToken(IRTextTokens.NUM_SUB_INT_KEY));
    putAll(map, IRTextTokens.NUM_SUB_CPLX, getToken(IRTextTokens.NUM_SUB_CPLX_KEY));
    putAll(map, IRTextTokens.UNDEFINED, getToken(IRTextTokens.UNDEFINED_KEY));

    // usually not in default partition
    putAll(map, IRTextTokens.STRING, getToken(IRTextTokens.STRING_KEY));
    map.put(RTerminal.SYMBOL_G, getToken(IRTextTokens.STRING_KEY));
    map.put(RTerminal.SPECIAL, getToken(IRTextTokens.OP_KEY));
    putAll(map, IRTextTokens.COMMENT, getToken(IRTextTokens.COMMENT_KEY));
  }
示例#23
0
 @Override
 public void actionPerformed(ActionEvent e) {
   for (Shp shp : shapes.keySet()) {
     JRadioButton button = shapes.get(shp);
     if (button.isSelected()) {
       SmedAction.panelMain.mark.setShape(shp);
       SmedAction.panelMain.mark.setObject(objects.get(shp));
       button.setBorderPainted(true);
     } else {
       button.setBorderPainted(false);
     }
   }
   if (SmedAction.panelMain.mark.testValid()) {
     SmedAction.panelMain.panelChan.topmarkButton.setVisible(true);
     SmedAction.panelMain.panelChan.lightButton.setVisible(true);
     if (SmedAction.panelMain.mark.getCategory() == Cat.LAM_PORT) {
       switch (SmedAction.panelMain.mark.getRegion()) {
         case A:
           SmedAction.panelMain.mark.setObjPattern(Pat.NOPAT);
           SmedAction.panelMain.mark.setObjColour(Col.RED);
           break;
         case B:
           SmedAction.panelMain.mark.setObjPattern(Pat.NOPAT);
           SmedAction.panelMain.mark.setObjColour(Col.GREEN);
           break;
         case C:
           SmedAction.panelMain.mark.setObjPattern(Pat.HSTRP);
           SmedAction.panelMain.mark.setObjColour(Col.RED);
           SmedAction.panelMain.mark.addObjColour(Col.WHITE);
           SmedAction.panelMain.mark.addObjColour(Col.RED);
           SmedAction.panelMain.mark.addObjColour(Col.WHITE);
           break;
       }
     } else {
       SmedAction.panelMain.mark.setObjPattern(Pat.HSTRP);
       switch (SmedAction.panelMain.mark.getRegion()) {
         case A:
           SmedAction.panelMain.mark.setObjColour(Col.RED);
           SmedAction.panelMain.mark.addObjColour(Col.GREEN);
           SmedAction.panelMain.mark.addObjColour(Col.RED);
           break;
         case B:
           SmedAction.panelMain.mark.setObjColour(Col.GREEN);
           SmedAction.panelMain.mark.addObjColour(Col.RED);
           SmedAction.panelMain.mark.addObjColour(Col.GREEN);
           break;
         case C:
           SmedAction.panelMain.mark.setObjColour(Col.RED);
           SmedAction.panelMain.mark.addObjColour(Col.GREEN);
           SmedAction.panelMain.mark.addObjColour(Col.RED);
           SmedAction.panelMain.mark.addObjColour(Col.GREEN);
           break;
       }
     }
     SmedAction.panelMain.panelMore.syncPanel();
   } else {
     SmedAction.panelMain.panelChan.topmarkButton.setVisible(false);
     SmedAction.panelMain.panelChan.lightButton.setVisible(false);
   }
 }
示例#24
0
 /**
  * Turns the majority of the given percentage of floor cells into water cells, represented by '~'.
  * Water will be clustered into a random number of pools, with more appearing if needed to fill
  * the percentage. Each pool will have randomized volume that should fill or get very close to
  * filling the requested percentage, unless the pools encounter too much tight space. If this
  * DungeonGenerator previously had addWater called, the latest call will take precedence. No
  * islands will be placed with this variant, but the edge of the water will be shallow,
  * represented by ','.
  *
  * @param percentage the percentage of floor cells to fill with water
  * @return this DungeonGenerator; can be chained
  */
 public DungeonGenerator addWater(int percentage) {
   if (percentage < 0) percentage = 0;
   if (percentage > 100) percentage = 100;
   if (fx.containsKey(FillEffect.WATER)) fx.remove(FillEffect.WATER);
   fx.put(FillEffect.WATER, percentage);
   return this;
 }
 /**
  * Another satisfy for continuous data types. Indicates whether a particular value is higher or
  * lower (as specified by theDirection) than the upper or lower threshold.
  *
  * <p>
  *
  * @param theGeneticDataType
  * @return true if the value is satisfied by the specified inequalities in the spec
  */
 public boolean satisfy(GeneticDataTypes theGeneticDataType, float value, Direction theDirection)
     throws IllegalArgumentException {
   if (!theGeneticDataType.getTheDataTypeCategory().equals(DataTypeCategory.Continuous)) {
     throw new IllegalArgumentException(
         "satisfy for continuous data types only takes continuous GeneticDataTypes");
   }
   ResultDataTypeSpec theResultDataTypeSpec = finalDataTypeSpecs.get(theGeneticDataType);
   if (null == theResultDataTypeSpec) {
     return false;
   }
   if (theResultDataTypeSpec.acceptAll) {
     return true;
   }
   switch (theDirection) {
     case higher:
       return (theResultDataTypeSpec.combinedGreaterContinuousDataTypeSpec != null
           && finalDataTypeSpecs
               .get(theGeneticDataType)
               .combinedGreaterContinuousDataTypeSpec
               .satisfy(value));
     case lower:
       return (theResultDataTypeSpec.combinedLesserContinuousDataTypeSpec != null
           && finalDataTypeSpecs
               .get(theGeneticDataType)
               .combinedLesserContinuousDataTypeSpec
               .satisfy(value));
   }
   // unreachable code; keep compiler happy
   // TODO: throw an exception
   return false;
 }
示例#26
0
 /**
  * Turns the given percentage of floor cells not already adjacent to walls into wall cells,
  * represented by '#'. If this DungeonGenerator previously had addBoulders called, the latest call
  * will take precedence.
  *
  * @param percentage the percentage of floor cells not adjacent to walls to fill with boulders.
  * @return this DungeonGenerator; can be chained
  */
 public DungeonGenerator addBoulders(int percentage) {
   if (percentage < 0) percentage = 0;
   if (percentage > 100) percentage = 100;
   if (fx.containsKey(FillEffect.BOULDERS)) fx.remove(FillEffect.BOULDERS);
   fx.put(FillEffect.BOULDERS, percentage);
   return this;
 }
示例#27
0
 public static void main(String[] args) {
   EnumMap<AlarmPoints, Command> em = new EnumMap<AlarmPoints, Command>(AlarmPoints.class);
   em.put(
       KITCHEN,
       new Command() {
         public void action() {
           print("Kitchen fire!");
         }
       });
   em.put(
       BATHROOM,
       new Command() {
         public void action() {
           print("Bathroom alert!");
         }
       });
   for (Map.Entry<AlarmPoints, Command> e : em.entrySet()) {
     printnb(e.getKey() + ": ");
     e.getValue().action();
   }
   try { // If there's no value for a particular key:
     em.get(UTILITY).action();
   } catch (Exception e) {
     print(e);
   }
 }
示例#28
0
 /**
  * Turns the given percentage of open area floor cells into trap cells, represented by '^'.
  * Corridors that have no possible way to move around a trap will not receive traps, ever. If this
  * DungeonGenerator previously had addTraps called, the latest call will take precedence.
  *
  * @param percentage the percentage of valid cells to fill with traps; should be no higher than 5
  *     unless the dungeon floor is meant to be a kill screen or minefield.
  * @return this DungeonGenerator; can be chained
  */
 public DungeonGenerator addTraps(int percentage) {
   if (percentage < 0) percentage = 0;
   if (percentage > 100) percentage = 100;
   if (fx.containsKey(FillEffect.TRAPS)) fx.remove(FillEffect.TRAPS);
   fx.put(FillEffect.TRAPS, percentage);
   return this;
 }
 private static void doAttributes(final Creature cr, final CreatureType ct) {
   int attnum = ct.attnum.aValue();
   final EnumMap<Attribute, Integer> attcap = new EnumMap<Attribute, Integer>(Attribute.class);
   for (final Attribute at : Attribute.values()) {
     if (ct.attributeCap.containsKey(at)) {
       attcap.put(at, ct.attributeCap.get(at).aValue());
     } else {
       attcap.put(at, 10);
     }
   }
   for (final Attribute a : Attribute.values()) {
     attnum -= Math.min(4, cr.skill().getAttribute(a, false));
   }
   while (attnum > 0) {
     Attribute a = i.rng.randFromArray(Attribute.values());
     if (a == WISDOM && cr.alignment() == Alignment.LIBERAL && i.rng.likely(4)) {
       a = HEART;
     }
     if (a == HEART && cr.alignment() == Alignment.CONSERVATIVE && i.rng.likely(4)) {
       a = WISDOM;
     }
     if (cr.skill().getAttribute(a, false) < attcap.get(a)) {
       cr.skill().attribute(a, +1);
       attnum--;
     }
   }
 }
示例#30
0
  public void testAddRemove() {
    // add 10000 new nodes
    start = System.currentTimeMillis();
    for (int i = 0; i < 10000; i++) g.addNode("__newnode__" + i);
    end = System.currentTimeMillis();
    measureValues.put(Measures.ADD_NODE, end - start);

    // for each new node n, add 100 edges between n and old nodes
    start = System.currentTimeMillis();
    int current = 0;
    int edgeId = 0;
    for (int i = 0; i < 10000; i++) {
      String id = "__newnode__" + i;
      for (int j = 0; j < 100; j++) {
        g.addEdge("__newedge__" + edgeId, id, nodeIds.get(current));
        edgeId++;
        current++;
        if (current == nodeIds.size()) current = 0;
      }
    }
    end = System.currentTimeMillis();
    measureValues.put(Measures.ADD_EDGE, end - start);

    // remove all the new nodes (and new edges)
    start = System.currentTimeMillis();
    for (int i = 0; i < 10000; i++) g.removeNode("__newnode__" + i);
    end = System.currentTimeMillis();
    measureValues.put(Measures.REMOVE_NODE, end - start);

    // remove 10000 edges
    start = System.currentTimeMillis();
    for (int i = 0; i < 10000; i++) g.removeEdge(edgeIds.get(i));
    end = System.currentTimeMillis();
    measureValues.put(Measures.REMOVE_EDGE, end - start);
  }