@Test
 public void itAddsNewCategories() {
   Category category = new Category();
   category.setName("Salads");
   categoryDAO.create(category);
   assertEquals("Salads", categoryDAO.find((long) 3).getName());
 }
  private void init(Context context, CreditsParams p) {
    Paint paintPerson = new Paint();
    paintPerson.setAntiAlias(true);
    paintPerson.setStrokeWidth(5);
    paintPerson.setStrokeCap(Paint.Cap.ROUND);
    paintPerson.setTextSize(p.getTextSizeDefault());
    paintPerson.setTypeface(p.getTypefaceDefault());
    paintPerson.setColor(p.getColorDefault());
    paintPerson.setTextAlign(Paint.Align.CENTER);

    Person.setPaint(paintPerson);
    Person.setSpacings(p.getSpacingBeforeDefault(), p.getSpacingAfterDefault());

    Paint paintCategory = new Paint();
    paintCategory.setAntiAlias(true);
    paintCategory.setStrokeWidth(5);
    paintCategory.setStrokeCap(Paint.Cap.ROUND);
    paintCategory.setTextSize(p.getTextSizeCategory());
    paintCategory.setTypeface(p.getTypefaceCategory());
    paintCategory.setColor(p.getColorCategory());
    paintCategory.setTextAlign(Paint.Align.CENTER);

    Category.setPaint(paintCategory);
    Category.setSpacings(p.getSpacingBeforeCategory(), p.getSpacingAfterCategory());

    credits.add(new Person(context.getString(p.getAppNameRes())));
    credits.add(new Category(context.getString(p.getAppVersionRes())));
    loadFromResources(credits, p.getArrayCreditsRes());

    mBackground = BitmapFactory.decodeResource(getResources(), p.getBitmapBackgroundRes());
    mBackgroundLandscape =
        BitmapFactory.decodeResource(getResources(), p.getBitmapBackgroundLandscapeRes());
  }
Beispiel #3
0
 /**
  * Loads new test with given name and ConfigurationSection.
  *
  * @param plugin instance of BetonTest
  * @param name name of the test
  * @param config section containing the test
  * @throws TestException when configuration is incorrect
  */
 public Test(BetonTest plugin, String name, ConfigurationSection config) throws TestException {
   this.plugin = plugin;
   this.name = name;
   messageStart = config.getString("messages.start");
   messageResume = config.getString("messages.resume");
   messagePass = config.getString("messages.pass");
   messageFail = config.getString("messages.fail");
   messagePause = config.getString("messages.pause");
   commandWin = config.getString("commands.pass");
   commandFail = config.getString("commands.fail");
   commandPause = config.getString("commands.pause");
   blockedCommands = config.getStringList("blocked_cmds");
   teleportBack = config.getBoolean("teleport_back");
   maxMistakes = config.getInt("max_mistakes", -1);
   if (maxMistakes < 0) throw new TestException("max_mistakes must be more than 0");
   onMistake = MistakeAction.match(config.getString("on_mistake"));
   if (onMistake == null) throw new TestException("incorrect on_mistake value");
   if (config.getConfigurationSection("categories") == null)
     throw new TestException("categories not defined");
   for (String key : config.getConfigurationSection("categories").getKeys(false)) {
     try {
       categories.add(
           new Category(plugin, this, key, config.getConfigurationSection("categories." + key)));
     } catch (CategoryException e) {
       throw new TestException("error in '" + key + "' category: " + e.getMessage());
     }
   }
   if (categories.isEmpty()) throw new TestException("categories not defined");
   for (Category category : categories) {
     category.shuffle();
   }
 }
  /**
   * Gets the category by event.
   *
   * @param event_id the event_id
   * @return the category by event
   */
  public Category getCategoryByEvent(long event_id) {
    Category ct = new Category();
    String selectQuery =
        "SELECT  * FROM "
            + TABLE_CATEGORY
            + " tc, "
            + TABLE_EVENT
            + " te, "
            + TABLE_CATEGORY_EVENT
            + " ce WHERE te."
            + KEY_ID
            + " = "
            + event_id
            + " AND tc."
            + KEY_ID
            + " = "
            + "ce."
            + KEY_CATEGORY_ID
            + " AND te."
            + KEY_ID
            + " = "
            + "ce."
            + KEY_EVENT_ID;

    Log.e("In getCategoryByEvent", selectQuery);
    SQLiteDatabase db = this.getReadableDatabase();
    Cursor c = db.rawQuery(selectQuery, null);

    if (c.moveToFirst()) {
      ct.setId(c.getLong((c.getColumnIndex(KEY_CATEGORY_ID))));
      ct.setName(c.getString(c.getColumnIndex(KEY_CATEGORY_NAME)));
      ct.setColor(c.getString(c.getColumnIndex(KEY_CATEGORY_COLOR)));
    }
    return ct;
  }
Beispiel #5
0
  private Category createCategory(Organization organization) {
    Category category = new Category();
    category.setName("Test Category");
    category.setOrganization(organization);

    return category;
  }
Beispiel #6
0
 /**
  * Starts the test for the player.
  *
  * @param player
  */
 public void startTest(Player player) {
   if (plugin.getTest(player) != null) return;
   plugin.getData().set(player.getUniqueId() + ".current.name", name);
   plugin.getData().set(player.getUniqueId() + ".current.chances", maxMistakes);
   plugin
       .getData()
       .set(
           player.getUniqueId() + ".location",
           player.getLocation().getX()
               + ";"
               + player.getLocation().getY()
               + ";"
               + player.getLocation().getZ()
               + ";"
               + player.getLocation().getWorld().getName()
               + ";"
               + player.getLocation().getYaw()
               + ";"
               + player.getLocation().getPitch());
   Category first = categories.get(0);
   players.put(player.getUniqueId(), first);
   chances.put(player.getUniqueId(), maxMistakes);
   if (messageStart != null) player.sendMessage(messageStart.replace('&', '§'));
   first.addPlayer(player);
   new Saver(plugin);
 }
  @SuppressWarnings({"unchecked"})
  private void cleanup() {
    EntityManager em = getOrCreateEntityManager();
    em.getTransaction().begin();

    for (Hoarder hoarder : (List<Hoarder>) em.createQuery("from Hoarder").getResultList()) {
      hoarder.getItems().clear();
      em.remove(hoarder);
    }

    for (Category category : (List<Category>) em.createQuery("from Category").getResultList()) {
      if (category.getExampleItem() != null) {
        category.setExampleItem(null);
        em.remove(category);
      }
    }

    for (Item item : (List<Item>) em.createQuery("from Item").getResultList()) {
      item.setCategory(null);
      em.remove(item);
    }

    em.createQuery("delete from Item").executeUpdate();

    em.getTransaction().commit();
    em.close();
  }
  protected List<Category> exportCategories() {
    if (!this.running) return null;

    // get user configured column names and sql
    String colId = (String) this.properties.get(PROPKEY_CAT_ID);
    String colName = (String) this.properties.get(PROPKEY_CAT_NAME);
    String table = (String) this.properties.get(PROPKEY_CAT_TABLE);
    String rawSql = (String) this.properties.get(PROPKEY_CAT_SQL);
    // update sql to reflect user configured column names
    String sql = rawSql.replaceAll("\\Q{" + PROPKEY_CAT_ID + "}\\E", colId);
    sql = sql.replaceAll("\\Q{" + PROPKEY_CAT_NAME + "}\\E", colName);
    sql = sql.replaceAll("\\Q{" + PROPKEY_CAT_TABLE + "}\\E", table);

    Vector<Category> categories = new Vector<Category>();

    ResultSet data = null;
    try {
      data = sql(sql);
      while (data.next()) { // get each category
        Category cat = new Category();
        cat.id = data.getString(colId);
        cat.name = encode(data.getBytes(colName));
        categories.add(cat);
      }
    } catch (SQLException e) {
      log.error("Could not export Categories with sql: " + sql);
      e.printStackTrace();
      return null;
    }
    return categories;
  }
  public void createdFormatedShoppingList() {

    this.formatedProductsList = new HashMap<String, List<String>>();
    this.formatedCategoriesList = new ArrayList<String>();

    Iterator<Category> iterateur = categoriesListe.iterator();

    while (iterateur.hasNext()) {
      Category category = iterateur.next();
      String categoryString = category.getName();
      int idCateg = category.getId();

      this.formatedCategoriesList.add(categoryString);

      List<String> donneesCategory = new ArrayList<String>();

      for (int c = 0; c < productsListe.size(); c++) {
        int prod_Idcateg = productsListe.get(c).getIdCateg();
        int prod_IsShop = productsListe.get(c).isShop();

        String unProduit = new String();
        if (prod_Idcateg == idCateg && prod_IsShop == 1) {
          unProduit = productsListe.get(c).getName();
          String quantity = productsListe.get(c).getQuantity();
          if (quantity != "" && quantity != null) {
            unProduit += " : " + quantity;
          }
          donneesCategory.add(unProduit);
        }
      }

      this.formatedProductsList.put(categoryString, donneesCategory);
    }
  }
Beispiel #10
0
 @Override
 public String toString() {
   StringBuffer sb = new StringBuffer();
   /** chart */
   sb.append("\t\"<chart ");
   sb.append(formap(this.chart.getAttrs()));
   sb.append(" >\" +\n \n");
   /** categories */
   if (categories.size() > 0) {
     sb.append("\t\t\"<categories>\"+\n");
     for (Category category : categories) {
       sb.append("\t\t\t\"<category ");
       sb.append(formap(category.getAttrs()));
       sb.append(" />\"+\n");
     }
     sb.append("\t\t\"</categories>\"+\n\n");
   }
   if (dataSets.size() > 0) {
     for (DataSet dataset : dataSets) {
       sb.append("\t\t\"<dataset ");
       sb.append(formap(dataset.getAttrs()));
       sb.append(" >\"+\n");
       for (Set set : dataset.getSets()) {
         sb.append("\t\t\t\"<set ");
         sb.append(formap(set.getAttrs()));
         sb.append(" />\"+\n");
       }
       sb.append("\t\t\"</dataset>\"+\n\n");
     }
   }
   sb.append("\t\"</chart>\"\n");
   return sb.toString();
 }
Beispiel #11
0
 public static Category createCategory(EOEditingContext editingContext, Integer id, String name) {
   Category eo =
       (Category) EOUtilities.createAndInsertInstance(editingContext, _Category.ENTITY_NAME);
   eo.setId(id);
   eo.setName(name);
   return eo;
 }
  public void displayConfusionMatrix() {
    int total = 0;
    int wrong = 0;
    System.out.print("  |   ");
    for (Category c : categories.values()) {
      System.out.print(c.getCategory() + "  |   ");
      total += c.totalCategorized;
      wrong += c.wrong;
    }
    System.out.println();

    for (Category c : categories.values()) {
      String out = c.getCategory() + " | ";
      for (String c2 : categories.keySet()) {
        if (c.categorized.containsKey(c2))
          out += String.format("%.2f | ", c.categorized.get(c2) / (c.totalCategorized * 1.0));
        else out += "0000 | ";
      }
      System.out.println(out);
    }

    System.out.println("Accuracy: " + Math.round(100 * (total - wrong * 1.0) / total) + "%");

    System.out.println();
  }
  @SuppressWarnings({"unchecked"})
  private void cleanup() {
    Session s = openSession();
    s.beginTransaction();

    s.createQuery("delete from SubItem").executeUpdate();
    for (Hoarder hoarder : (List<Hoarder>) s.createQuery("from Hoarder").list()) {
      hoarder.getItems().clear();
      s.delete(hoarder);
    }

    for (Category category : (List<Category>) s.createQuery("from Category").list()) {
      if (category.getExampleItem() != null) {
        category.setExampleItem(null);
        s.delete(category);
      }
    }

    for (Item item : (List<Item>) s.createQuery("from Item").list()) {
      item.setCategory(null);
      s.delete(item);
    }

    s.createQuery("delete from Item").executeUpdate();

    s.getTransaction().commit();
    s.close();
  }
Beispiel #14
0
  public static void main(String[] args) {
    Predictor p = Predictor.getInstance();
    Map<Category, Double> m = p.getPrediction(1, 2, "2");
    Set<Category> categories = m.keySet();
    Category[] cats = new Category[categories.size()];
    categories.toArray(cats);
    Arrays.sort(
        cats,
        new Comparator<Category>() {
          @Override
          public int compare(Category o1, Category o2) {
            return -(int) (100000 * (m.get(o1) - m.get(o2)));
          }
        });

    double sum = 0.0;
    for (Category c : cats) {
      sum += m.get(c);
    }

    for (Category c : cats) {

      System.out.println(String.format("%-10s ->   %7.4f %%", c.getType(), m.get(c) / sum * 100));
    }
  }
 @Test
 public void itUpdatesCategory() {
   Category category = categoryDAO.find((long) 1);
   category.setName("Salads");
   categoryDAO.update(category);
   assertEquals("Salads", categoryDAO.find((long) 1).getName());
 }
  @Test
  public void testMergeMultipleEntityCopiesAllowedAndDisallowed() {
    Item item1 = new Item();
    item1.setName("item1 name");
    Category category = new Category();
    category.setName("category");
    item1.setCategory(category);
    category.setExampleItem(item1);

    EntityManager em = getOrCreateEntityManager();
    em.getTransaction().begin();
    em.persist(item1);
    em.getTransaction().commit();
    em.close();

    // get another representation of item1
    em = getOrCreateEntityManager();
    em.getTransaction().begin();
    Item item1_1 = em.find(Item.class, item1.getId());
    // make sure item1_1.category is initialized
    Hibernate.initialize(item1_1.getCategory());
    em.getTransaction().commit();
    em.close();

    em = getOrCreateEntityManager();
    em.getTransaction().begin();
    Item item1Merged = em.merge(item1);

    // make sure item1Merged.category is also managed
    Hibernate.initialize(item1Merged.getCategory());

    item1Merged.setCategory(category);
    category.setExampleItem(item1_1);

    // now item1Merged is managed and it has a nested detached item
    // and there is  multiple managed/detached Category objects
    try {
      // the following should fail because multiple copies of Category objects is not allowed by
      // CustomEntityCopyObserver
      em.merge(item1Merged);
      fail(
          "should have failed because CustomEntityCopyObserver does not allow multiple copies of a Category. ");
    } catch (IllegalStateException ex) {
      // expected
    } finally {
      em.getTransaction().rollback();
    }
    em.close();

    em = getOrCreateEntityManager();
    em.getTransaction().begin();
    item1 = em.find(Item.class, item1.getId());
    assertEquals(category.getName(), item1.getCategory().getName());
    assertSame(item1, item1.getCategory().getExampleItem());
    em.getTransaction().commit();
    em.close();

    cleanup();
  }
  /**
   * Calculates casing information using data from the specified CLDRFile.
   *
   * @param resolved the resolved CLDRFile to calculate casing information from
   * @return
   */
  public static Map<Category, CasingType> getSamples(CLDRFile resolved) {
    // Use EnumMap instead of an array for type safety.
    Map<Category, Counter<CasingType>> counters =
        new EnumMap<Category, Counter<CasingType>>(Category.class);

    for (Category category : Category.values()) {
      counters.put(category, new Counter<CasingType>());
    }
    PathStarrer starrer = new PathStarrer();
    boolean isRoot = "root".equals(resolved.getLocaleID());
    Set<String> missing = !DEBUG ? null : new TreeSet<String>();

    for (String path : resolved) {
      if (!isRoot) {
        String locale2 = resolved.getSourceLocaleID(path, null);
        if (locale2.equals("root") || locale2.equals("code-fallback")) {
          continue;
        }
      }
      String winningPath = resolved.getWinningPath(path);
      if (!winningPath.equals(path)) {
        continue;
      }
      Category category = getCategory(path);
      if (category != null) {
        String value = resolved.getStringValue(path);
        if (value == null || value.length() == 0) continue;
        CasingType ft = CasingType.from(value);
        counters.get(category).add(ft, 1);
      } else if (DEBUG) {
        String starred = starrer.set(path);
        missing.add(starred);
      }
    }

    Map<Category, CasingType> info = new EnumMap<Category, CasingType>(Category.class);
    for (Category category : Category.values()) {
      if (category == Category.NOT_USED) continue;
      Counter<CasingType> counter = counters.get(category);
      long countLower = counter.getCount(CasingType.lowercase);
      long countUpper = counter.getCount(CasingType.titlecase);
      long countOther = counter.getCount(CasingType.other);
      CasingType type;
      if (countLower + countUpper == 0) {
        type = CasingType.other;
      } else if (countLower >= countUpper * MIN_FACTOR && countLower >= countOther) {
        type = CasingType.lowercase;
      } else if (countUpper >= countLower * MIN_FACTOR && countUpper >= countOther) {
        type = CasingType.titlecase;
      } else {
        type = CasingType.other;
      }
      info.put(category, type);
    }
    if (DEBUG && missing.size() != 0) {
      System.out.println("Paths skipped:\n" + CollectionUtilities.join(missing, "\n"));
    }
    return info;
  }
Beispiel #18
0
 public double getTotalRemaining() {
   List<Category> categories = this.getCategories();
   double remaining = 0.0;
   for (Category category : categories) {
     remaining += category.getRemaining();
   }
   return remaining;
 }
Beispiel #19
0
  /**
   * Gets the children.
   *
   * @param id category id
   * @return List of children of certain category
   */
  public LinkedList<Category> getChildren(long id) {
    LinkedList<Category> toReturn = new LinkedList<Category>();
    for (Category c : this.categories.findAll()) {
      if (c.getPredecessor() == id) toReturn.add(c);
    }

    return toReturn;
  }
Beispiel #20
0
  @Test
  public void hashCodeShouldNotBeEqual() {

    Category category1 = new Category("john", "desc", true, false);
    Category category2 = new Category("bob", "desc", true, false);

    assertNotSame(category1.hashCode(), category2.hashCode());
  }
Beispiel #21
0
  @Test
  public void equalsReturnsFalseWhenNotEqual() {

    Category category1 = new Category("john", "desc", true, false);
    Category category2 = new Category("bob", "desc", true, false);

    assertFalse(category1.equals(category2));
  }
Beispiel #22
0
  @Test
  public void equalsReturnsTrueWhenEqual() {

    Category category1 = new Category("john", "desc", true, false);
    Category category2 = new Category("john", "desc", true, false);

    assertTrue(category1.equals(category2));
  }
 /*
  * Return true if all the items on the board have been used
  */
 public boolean isEmpty() {
   for (Category category : categories) {
     if (category.isUsedUp() == false) {
       return false;
     }
   }
   return true;
 }
 // implements ACollection
 // the type attribute is not used for Categories
 protected void newItem(Long aType, boolean isDefault) {
   Category newCategory = null;
   newCategory = Category.newItem(isDefault);
   items.put(newCategory.getId(), newCategory);
   setCurrentItem(newCategory.getId());
   // save needed
   sendSaveNeeded();
 } // END public void newItem(String)
Beispiel #25
0
 public Category mapRow(ResultSet rs, int rowNum) throws SQLException {
   Category category = new Category();
   category.setId(rs.getLong("id"));
   category.setName(rs.getString("name"));
   category.setShowOnSalesScreen(rs.getBoolean("showOnSalesScreen"));
   category.setThumbnailId(rs.getLong("thumbnailId"));
   return category;
 }
Beispiel #26
0
 /** @return Total allocated for the categories */
 public double getCategoriesTotal() {
   List<Category> categories = this.getCategories();
   double total = 0.0;
   for (Category category : categories) {
     total += category.getTotal();
   }
   return total;
 }
Beispiel #27
0
 @Override
 public boolean equals(Object otherCategory) {
   if (!(otherCategory instanceof Category)) {
     return false;
   } else {
     Category newCategory = (Category) otherCategory;
     return this.getName().equals(newCategory.getName());
   }
 }
Beispiel #28
0
 public void deleteLearnCategories() {
   ArrayList<Category> learnCategories = learnGraph.getCategories();
   for (Category c : learnCategories) {
     Nodemapper n = brain.findNode(c);
     System.out.println("Found node " + n + " for " + c.inputThatTopic());
     if (n != null) n.category = null;
   }
   learnGraph = new Graphmaster(this);
 }
 public SparseIntArray buildCategoryIndex(ArrayList<Category> myCategoryList) {
   SparseIntArray myPositionMap = new SparseIntArray();
   Integer position = 0;
   for (Category myCat : myCategoryList) {
     myPositionMap.put(myCat.getID(), position);
     position++;
   }
   return myPositionMap;
 }
Beispiel #30
0
 @Test
 public void save_savesCategoryIdIntoDB_true() {
   Category myCategory = new Category("Household chores");
   myCategory.save();
   Task myTask = new Task("Mow the lawn", myCategory.getId());
   myTask.save();
   Task savedTask = Task.find(myTask.getId());
   assertEquals(savedTask.getCategoryId(), myCategory.getId());
 }