コード例 #1
0
  @Test
  public void testToStringOrder() {

    Map<String, JobParameter> props = parameters.getParameters();
    StringBuffer stringBuilder = new StringBuffer();
    for (Entry<String, JobParameter> entry : props.entrySet()) {
      stringBuilder.append(entry.toString() + ";");
    }

    String string1 = stringBuilder.toString();

    Map<String, JobParameter> parameterMap = new HashMap<String, JobParameter>();
    parameterMap.put("string.key2", new JobParameter("value2"));
    parameterMap.put("string.key1", new JobParameter("value1"));
    parameterMap.put("long.key2", new JobParameter(2L));
    parameterMap.put("long.key1", new JobParameter(1L));
    parameterMap.put("double.key2", new JobParameter(2.2));
    parameterMap.put("double.key1", new JobParameter(1.1));
    parameterMap.put("date.key2", new JobParameter(date2));
    parameterMap.put("date.key1", new JobParameter(date1));

    JobParameters testProps = new JobParameters(parameterMap);

    props = testProps.getParameters();
    stringBuilder = new StringBuffer();
    for (Entry<String, JobParameter> entry : props.entrySet()) {
      stringBuilder.append(entry.toString() + ";");
    }
    String string2 = stringBuilder.toString();

    assertEquals(string1, string2);
  }
コード例 #2
0
  public void testToString() {
    final Key<String> key1 = Key.get(String.class, Names.named("KEY"));
    final Key<String> key2 = Key.get(String.class, Names.named("BAD"));

    final Injector injector =
        Guice.createInjector(
            new AbstractModule() {
              @Override
              protected void configure() {
                bind(key1).toProvider(new ToStringProvider());
                bind(key2).toProvider(new BadToStringProvider());
              }
            });

    final Entry<Named, String> entry1 =
        new LazyBeanEntry<Named, String>(
            (Named) key1.getAnnotation(), injector.getBinding(key1), 0);
    final Entry<Named, String> entry2 =
        new LazyBeanEntry<Named, String>(
            (Named) key2.getAnnotation(), injector.getBinding(key2), 0);

    Exception error = null;
    try {
      injector.getInstance(key2);
    } catch (final Exception e) {
      error = e;
    }

    assertEquals('@' + javax.inject.Named.class.getName() + "(value=KEY)=VALUE", entry1.toString());
    assertEquals(
        '@' + javax.inject.Named.class.getName() + "(value=BAD)=" + error, entry2.toString());
  }
コード例 #3
0
 /**
  * Test method for {@link Monitor#getServicePerformance()}.
  *
  * @throws ConnectionException
  */
 @Test
 public final void testGetServicePerformance1() throws ConnectionException {
   final Monitor conn = new Monitor(scalarisNode);
   try {
     final GetServicePerformanceResult nodePerformance = conn.getServicePerformance();
     for (final Entry<Long, Double> latencyAvg : nodePerformance.latencyAvg.entrySet()) {
       assertTrue(latencyAvg.toString(), latencyAvg.getKey() >= 0);
       assertTrue(latencyAvg.toString(), latencyAvg.getValue() >= 0);
     }
     for (final Entry<Long, Double> latencyStddev : nodePerformance.latencyStddev.entrySet()) {
       assertTrue(latencyStddev.toString(), latencyStddev.getKey() >= 0);
       assertTrue(latencyStddev.toString(), latencyStddev.getValue() >= 0);
     }
   } finally {
     conn.closeConnection();
   }
 }
コード例 #4
0
ファイル: Skill.java プロジェクト: a2937/ANSSRPG
 @Override
 public void execute(ICommandSender player, String[] p_71515_2_) {
   EntityPlayerMP user = (EntityPlayerMP) player;
   PlayerData playerData = PlayerStore.getInstance().getPlayer(user.getPersistentID().toString());
   String toReturn = "You have the current perks: ";
   for (Slug slug : playerData.getPerkList()) {
     toReturn += "," + slug;
   }
   toReturn += "| Your skill XP: ";
   for (Entry<String, Integer> skill : playerData.getSkillExp().entrySet()) {
     toReturn += skill.toString();
   }
   player.addChatMessage(new ChatComponentText(toReturn));
 }
コード例 #5
0
  /**
   * @param key - URI a unique identifier for a specific instance of data or set of data.
   * @param parameters - Map<ConfigKey name, Object value> name and value pairs of data. Note that
   *     the Map is required but it may be empty. However, the map itself cannot be null. The
   *     command line data provider requires that the orignal URI is available in the parameters map
   *     using the name "originalUri".
   * @return Object - The data associated with the URI or NoDataFound if this data provider did not
   *     find any data. This allows the data provider to return a null value (as a valid value).
   *     <p>The command line data provider cannot return a null value the most it can return is an
   *     empty string because it is not possible to pass null into the command line.
   */
  public Entry<URI, Object> locate(URI key, Map<MagicKey, Object> parameters) {

    String value = null;
    Entry<URI, Object> property = null;
    String keyAsString = key.toASCIIString();

    if ((keyAsString != null) && (!keyAsString.trim().isEmpty())) {

      // We want to check to see if the system property map contains
      // the key (if it does not contain the key then an override is
      // not going to occur. There is the case where the override can
      // be to remove a property (aka the value is empty).
      if (System.getProperties().containsKey(keyAsString)) {
        value = System.getProperty(keyAsString);
      }

      URI originalUri = (URI) parameters.get(MagicKey.ORIGINAL_URI);
      URI locatedUri = key;

      if (value != null) {

        parameters.put(MagicKey.RESOLVED_URI, key);
        property = new LocatedProperty(originalUri, locatedUri, value, this.getClass());

        if (LOG.isDebugEnabled()) {
          LOG.debug(property.toString());
        }
      } else {
        property = new MissingProperty(originalUri, locatedUri, this.getClass());
        if (LOG.isTraceEnabled()) {
          LOG.trace(property.toString());
        }
      }
    }
    return property;
  }
コード例 #6
0
ファイル: ImmutableMapTest.java プロジェクト: CenxuiMia/guava
    @Override
    protected void assertMoreInvariants(Map<K, V> map) {
      // TODO: can these be moved to MapInterfaceTest?
      for (Entry<K, V> entry : map.entrySet()) {
        assertEquals(entry.getKey() + "=" + entry.getValue(), entry.toString());
      }

      assertEquals("{" + joiner.join(map.entrySet()) + "}", map.toString());
      assertEquals("[" + joiner.join(map.entrySet()) + "]", map.entrySet().toString());
      assertEquals("[" + joiner.join(map.keySet()) + "]", map.keySet().toString());
      assertEquals("[" + joiner.join(map.values()) + "]", map.values().toString());

      assertEquals(MinimalSet.from(map.entrySet()), map.entrySet());
      assertEquals(Sets.newHashSet(map.keySet()), map.keySet());
    }
コード例 #7
0
ファイル: ImmutableBiMapTest.java プロジェクト: cushon/guava
    @Override
    protected void assertMoreInvariants(Map<K, V> map) {

      BiMap<K, V> bimap = (BiMap<K, V>) map;

      for (Entry<K, V> entry : map.entrySet()) {
        assertEquals(entry.getKey() + "=" + entry.getValue(), entry.toString());
        assertEquals(entry.getKey(), bimap.inverse().get(entry.getValue()));
      }

      assertEquals("{" + joiner.join(map.entrySet()) + "}", map.toString());
      assertEquals("[" + joiner.join(map.entrySet()) + "]", map.entrySet().toString());
      assertEquals("[" + joiner.join(map.keySet()) + "]", map.keySet().toString());
      assertEquals("[" + joiner.join(map.values()) + "]", map.values().toString());

      assertEquals(Sets.newHashSet(map.entrySet()), map.entrySet());
      assertEquals(Sets.newHashSet(map.keySet()), map.keySet());
    }
コード例 #8
0
 private static ArrayList<Double> cosineScore(ArrayList<String> query) {
   ArrayList<Double> relevantDocs = new ArrayList<Double>();
   Map<String, Double> scores = new HashMap<String, Double>();
   for (String term : query) {
     Integer termID = termsIDSMap.get(term).intValue();
     LinkedTreeMap<String, Double> postingsList = reverseIndex.get(termID.toString());
     int docFreq = postingsList.size();
     // Weight in query later
     for (Entry<String, Double> docEntry : postingsList.entrySet()) {
       String docID = docEntry.getKey();
       Double tf_idf = docEntry.getValue();
       scores.putIfAbsent(docID, 0d);
       Double score = scores.get(docID);
       scores.put(docID, score + tf_idf);
     }
   }
   for (Entry<String, Double> entry : scores.entrySet()) {
     System.out.println(entry.toString());
   }
   // normalize with magnitude later
   return relevantDocs;
 }
コード例 #9
0
ファイル: Database.java プロジェクト: jajja/jorm
  private void __configure(Properties properties) {
    for (Entry<Object, Object> property : properties.entrySet()) {
      String[] parts = ((String) property.getKey()).split("\\.");
      boolean isMalformed = false;

      if (parts[0].equals("database") && parts.length > 1) {
        String database = parts[1];

        Configuration configuration = configurations.get(database);
        if (configuration == null) {
          configuration = new Configuration(database);
          configurations.put(database, configuration);
        }

        String value = (String) property.getValue();
        switch (parts.length) {
          case 2:
            if (parts[1].equals("context")) {
              globalDefaultContext = value;
            } else {
              isMalformed = true;
            }
            break;

          case 3:
            if (parts[2].equals("destroyMethod")) {
              configuration.destroyMethodName = value;
            } else if (parts[2].equals("dataSource")) {
              configuration.dataSourceClassName = value;
            } else if (parts[2].equals("defaultContext")) {
              if (database.indexOf(Context.CONTEXT_SEPARATOR) != -1) {
                isMalformed = true;
              } else {
                defaultContext.put(database, value);
              }
            } else if (parts[2].equals("timeZone")) {
              if ("default".equalsIgnoreCase(value)) {
                configuration.calendar = null;
              } else {
                configuration.calendar = Calendar.getInstance(TimeZone.getTimeZone(value));
              }
            } else {
              isMalformed = true;
            }
            break;

          case 4:
            if (parts[2].equals("dataSource")) {
              configuration.dataSourceProperties.put(parts[3], value);
            } else {
              isMalformed = true;
            }
            break;

          default:
            isMalformed = true;
        }
      } else {
        isMalformed = true;
      }

      if (isMalformed) {
        throw new RuntimeException("Malformed jorm property: " + property.toString());
      }
    }
  }
コード例 #10
0
  private void kill(LivingEntity monster, MonsterHuntWorld world) {
    EntityDamageByEntityEvent event = (EntityDamageByEntityEvent) monster.getLastDamageCause();
    String name;
    Player player = null;

    String cause = "General";
    if (event.getCause() == DamageCause.PROJECTILE && event.getDamager() instanceof Projectile) {
      if (event.getDamager() instanceof Snowball) cause = "Snowball";
      else cause = "Arrow";
      LivingEntity shooter = ((Projectile) event.getDamager()).getShooter();
      if (shooter instanceof Player) player = (Player) shooter;
    } else if (event.getDamager() instanceof Wolf && ((Wolf) event.getDamager()).isTamed()) {
      cause = "Wolf";
      player = (Player) ((Wolf) event.getDamager()).getOwner();
    }

    if (player == null) {
      if (!(event.getDamager() instanceof Player)) return;
      player = (Player) event.getDamager();

      if (cause.equals("General")) {
        if (player.getItemInHand() == null) cause = String.valueOf(0);
        else cause = String.valueOf(player.getItemInHand().getTypeId());
      }
    }

    int points = 0;
    if (monster instanceof Skeleton) {
      points = world.settings.getMonsterValue("Skeleton", cause);
      name = "Skeleton";
    } else if (monster instanceof Spider) {
      points = world.settings.getMonsterValue("Spider", cause);
      name = "Spider";
    } else if (monster instanceof Creeper) {
      Creeper creeper = (Creeper) monster;
      if (creeper.isPowered()) {
        points = world.settings.getMonsterValue("ElectrifiedCreeper", cause);
        name = "Electrified Creeper";
      } else {
        points = world.settings.getMonsterValue("Creeper", cause);
        name = "Creeper";
      }
    } else if (monster instanceof Ghast) {
      points = world.settings.getMonsterValue("Ghast", cause);
      name = "Ghast";
    } else if (monster instanceof Slime) {
      points = world.settings.getMonsterValue("Slime", cause);
      name = "Slime";
    } else if (monster instanceof PigZombie) {
      points = world.settings.getMonsterValue("ZombiePigman", cause);
      name = "Zombie Pigman";
    } else if (monster instanceof Giant) {
      points = world.settings.getMonsterValue("Giant", cause);
      name = "Giant";
    } else if (monster instanceof Zombie) {
      points = world.settings.getMonsterValue("Zombie", cause);
      name = "Zombie";
    } else if (monster instanceof Wolf) {
      Wolf wolf = (Wolf) monster;
      if (wolf.isTamed()) {
        points = world.settings.getMonsterValue("TamedWolf", cause);
        name = "Tamed Wolf";
      } else {
        points = world.settings.getMonsterValue("WildWolf", cause);
        name = "Wild Wolf";
      }

    } else if (monster instanceof Player) {
      points = world.settings.getMonsterValue("Player", cause);
      name = "Player";
    } else if (monster instanceof Enderman) {
      points = world.settings.getMonsterValue("Enderman", cause);
      name = "Enderman";
    } else if (monster instanceof Silverfish) {
      points = world.settings.getMonsterValue("Silverfish", cause);
      name = "Silverfish";
    } else if (monster instanceof CaveSpider) {
      points = world.settings.getMonsterValue("CaveSpider", cause);
      name = "CaveSpider";
    } else if (monster instanceof EnderDragon) {
      points = world.settings.getMonsterValue("EnderDragon", cause);
      name = "Ender Dragon";
    } else if (monster instanceof MagmaCube) {
      points = world.settings.getMonsterValue("MagmaCube", cause);
      name = "Magma Cube";
    } else if (monster instanceof MushroomCow) {
      points = world.settings.getMonsterValue("Mooshroom", cause);
      name = "Mooshroom";
    } else if (monster instanceof Chicken) {
      points = world.settings.getMonsterValue("Chicken", cause);
      name = "Chicken";
    } else if (monster instanceof Cow) {
      points = world.settings.getMonsterValue("Cow", cause);
      name = "Cow";
    } else if (monster instanceof Blaze) {
      points = world.settings.getMonsterValue("Blaze", cause);
      name = "Blaze";
    } else if (monster instanceof Pig) {
      points = world.settings.getMonsterValue("Pig", cause);
      name = "Pig";
    } else if (monster instanceof Sheep) {
      points = world.settings.getMonsterValue("Sheep", cause);
      name = "Sheep";
    } else if (monster instanceof Snowman) {
      points = world.settings.getMonsterValue("SnowGolem", cause);
      name = "Snow Golem";
    } else if (monster instanceof Squid) {
      points = world.settings.getMonsterValue("Squid", cause);
      name = "Squid";
    } else if (monster instanceof Villager) {
      points = world.settings.getMonsterValue("Villager", cause);
      name = "Villager";
    } else {
      return;
    }
    if (points < 1) return;

    if (!world.Score.containsKey(player.getName())
        && !world.settings.getBoolean(Setting.EnableSignup)) world.Score.put(player.getName(), 0);
    if (world.Score.containsKey(player.getName())) {
      if (!(world.settings.getBoolean(Setting.OnlyCountMobsSpawnedOutsideBlackList)
              ^ world.properlyspawned.contains(monster.getEntityId()))
          && world.settings.getBoolean(Setting.OnlyCountMobsSpawnedOutside)) {
        String message = world.settings.getString(Setting.KillMobSpawnedInsideMessage);
        Util.Message(message, player);
        world.blacklist.add(monster.getEntityId());
        return;
      }
      int newscore = world.Score.get(player.getName()) + points;

      if (world.settings.getBoolean(Setting.AnnounceLead)) {
        Entry<String, Integer> leadpoints = null;
        for (Entry<String, Integer> e : world.Score.entrySet()) {
          if (leadpoints == null
              || e.getValue() > leadpoints.getValue()
              || (e.getValue() == leadpoints.getValue()
                  && leadpoints.getKey().equalsIgnoreCase(player.getName()))) {
            leadpoints = e;
          }
        }
        Util.Debug(leadpoints.toString());
        Util.Debug(String.valueOf(newscore));
        Util.Debug(String.valueOf(!leadpoints.getKey().equals(player.getName())));

        if (leadpoints != null
            && newscore > leadpoints.getValue()
            && !leadpoints.getKey().equals(player.getName())) {
          String message = world.settings.getString(Setting.MessageLead);
          message = message.replace("<Player>", player.getName());
          message = message.replace("<Points>", String.valueOf(newscore));
          message = message.replace("<World>", world.name);
          Util.Broadcast(message);
        }
      }

      world.Score.put(player.getName(), newscore);
      world.blacklist.add(monster.getEntityId());

      world.properlyspawned.remove((Object) monster.getEntityId());

      String message = world.settings.getKillMessage(cause);
      message = message.replace("<MobValue>", String.valueOf(points));
      message = message.replace("<MobName>", name);
      message = message.replace("<Points>", String.valueOf(newscore));
      Util.Message(message, player);
    }
  }
コード例 #11
0
 @Override
 public String toString() {
   return e.toString();
 }