コード例 #1
0
ファイル: MacRevised.java プロジェクト: rapodaca/cpsolver
  /**
   * After a value is unassigned: explanations of all values of unassigned variable are recomputed
   * ({@link Value#conflicts()}), propagation undo over the unassigned variable takes place.
   */
  @Override
  public void afterUnassigned(long iteration, T value) {
    sLogger.debug("After unassign " + value.variable().getName() + " = " + value.getName());
    iIteration = iteration;
    if (!isGood(value))
      sLogger.error(
          value.variable().getName()
              + " = "
              + value.getName()
              + " -- not good value unassigned (noGood:"
              + noGood(value)
              + ")");

    List<T> back = new ArrayList<T>(supportValues(value.variable()));
    for (T aValue : back) {
      if (aValue.variable().getAssignment() != null) {
        Set<T> noGood = new HashSet<T>(1);
        noGood.add(aValue.variable().getAssignment());
        setNoGood(aValue, noGood);
      } else setGood(aValue);
    }

    List<T> queue = new ArrayList<T>();
    for (T aValue : back) {
      if (!isGood(aValue) || revise(aValue)) queue.add(aValue);
    }

    propagate(queue);
  }
コード例 #2
0
ファイル: MacRevised.java プロジェクト: rapodaca/cpsolver
  /**
   * After a value is assigned: explanations of other values of the value's variable are reset (to
   * contain only the assigned value), propagation over the assigned variable takes place.
   */
  @Override
  public void afterAssigned(long iteration, T value) {
    sLogger.debug("After assign " + value.variable().getName() + " = " + value.getName());
    iIteration = iteration;
    if (!isGood(value)) {
      sLogger.warn(
          value.variable().getName()
              + " = "
              + value.getName()
              + " -- not good value assigned (noGood:"
              + noGood(value)
              + ")");
      setGood(value);
    }

    Set<T> noGood = new HashSet<T>(1);
    noGood.add(value);
    List<T> queue = new ArrayList<T>();
    for (Iterator<T> i = value.variable().values().iterator(); i.hasNext(); ) {
      T anotherValue = i.next();
      if (anotherValue.equals(value) || !isGood(anotherValue)) continue;
      setNoGood(anotherValue, noGood);
      queue.add(anotherValue);
    }
    propagate(queue);
  }
コード例 #3
0
 public static <T extends SceneGraphNode> HashMap<T, String> getUniqueNames(Collection<T> l) {
   HashMap<String, List<T>> nameMap = new HashMap<String, List<T>>();
   HashMap<T, String> r = new HashMap<T, String>();
   for (T c : l) {
     if (c == null) continue;
     String name = c.getName();
     List<T> cList = nameMap.get(c.getName());
     if (cList == null) {
       cList = new LinkedList<T>();
       nameMap.put(name, cList);
     }
     cList.add(c);
   }
   for (String name : nameMap.keySet()) {
     List<T> nodes = nameMap.get(name);
     if (nodes.size() > 1) {
       int index = 1;
       DecimalFormat df = new DecimalFormat("000");
       for (T c : nodes) {
         String newName = name + df.format(index);
         r.put(c, newName);
         index++;
       }
     } else {
       r.put(nodes.get(0), name);
     }
   }
   return r;
 }
コード例 #4
0
  static final <T extends Definition> List<T> filterExcludeInclude(
      List<T> definitions, String[] excludes, String[] includes) {
    List<T> result = new ArrayList<T>();

    definitionsLoop:
    for (T definition : definitions) {
      for (String exclude : excludes) {
        if (exclude != null
            && (definition.getName().matches(exclude.trim())
                || definition.getQualifiedName().matches(exclude.trim()))) {

          continue definitionsLoop;
        }
      }

      for (String include : includes) {
        if (include != null
            && (definition.getName().matches(include.trim())
                || definition.getQualifiedName().matches(include.trim()))) {

          result.add(definition);
          continue definitionsLoop;
        }
      }
    }

    return result;
  }
コード例 #5
0
ファイル: SimpleTree.java プロジェクト: burgerm/molgenis
  @Override
  public void setParent(T parent) {
    // does the parent already contain an element with my name
    if (parent != null && parent.get(name) != null) {
      throw new IllegalArgumentException(
          this.toString()
              + ".setParent("
              + parent.toString()
              + ") failed: a element already exists with name = '"
              + name
              + "', being "
              + parent.get(name));
    }

    // oh, and if there are any keys that are in both maps that map to
    // different objects, fail
    for (Object ckey : this.treeElements.keySet()) {
      for (Object pkey : parent.getTreeElements().keySet()) {
        if (pkey.equals(ckey)
            && !parent.getTreeElements().get(pkey).equals(this.treeElements.get(ckey))) {
          throw new IllegalArgumentException(
              "setParent(" + parent.getName() + "): duplicate child '" + ckey + "'/'" + pkey + "'");
        }
      }
    }
    // should keep all children, so merge with parent map
    for (Object ckey : treeElements.keySet()) {
      if (!parent.getTreeElements().containsValue(treeElements.get(ckey))) {
        parent.getTreeElements().put(ckey, this.treeElements.get(ckey));
      }
    }
    // parent.treeElements.putAll(this.treeElements);//damn things copies
    treeElements = parent.getTreeElements();
    parentName = parent.getName();
  }
コード例 #6
0
ファイル: MacRevised.java プロジェクト: rapodaca/cpsolver
 /** sets value's explanation */
 public void setNoGood(T value, Set<T> reason) {
   sLogger.debug(
       "    -- set nogood "
           + value.variable().getName()
           + " = "
           + value.getName()
           + "(expl:"
           + expl2str(reason)
           + ")");
   if (value.equals(value.variable().getAssignment())) {
     try {
       throw new Exception(
           "An assigned value "
               + value.variable().getName()
               + " = "
               + value.getName()
               + " become no good (noGood:"
               + reason
               + ")!!");
     } catch (Exception e) {
       sLogger.warn(e.getMessage(), e);
     }
     checkExpl(reason);
     printAssignments();
   }
   Set<T> noGood = noGood(value);
   if (noGood != null) for (T v : noGood) removeSupport(v.variable(), value);
   value.setExtra(reason);
   for (T aValue : reason) {
     addSupport(aValue.variable(), value);
   }
   goodnessChanged(value);
 }
コード例 #7
0
ファイル: DictionaryDaoImpl.java プロジェクト: Histler/Animau
 @Override
 protected ContentValues entityToContentValues(T entity) {
   ContentValues values = super.entityToContentValues(entity);
   if (!TextUtils.isEmpty(entity.getName())) {
     values.put(COLUMN_NAME, entity.getName());
   } else {
     values.putNull(COLUMN_NAME);
   }
   return values;
 }
コード例 #8
0
ファイル: StringUtil.java プロジェクト: hapm/SpoutAPI
 /**
  * Gets the named object with the shortest name from the values specified
  *
  * @param values to look into
  * @return the shortest value, or null if there are no values
  */
 public static <T extends Named> T getShortest(Collection<T> values) {
   int shortestMatch = Integer.MAX_VALUE;
   T shortest = null;
   for (T value : values) {
     if (value.getName().length() < shortestMatch) {
       shortestMatch = value.getName().length();
       shortest = value;
     }
   }
   return shortest;
 }
コード例 #9
0
  public void addVariable(T value) {

    if (containsKey(value.getName())) {
      throw ProcessEngineLogger.CORE_LOGGER.duplicateVariableInstanceException(value);
    }

    getVariablesMap().put(value.getName(), value);

    for (VariableStoreObserver<T> listener : observers) {
      listener.onAdd(value);
    }
  }
コード例 #10
0
ファイル: ClassDesc.java プロジェクト: wodis/itsnat_droid
  protected <T extends AttrDesc> void addAttrDescNoNS(T attrDesc) // NoNS no namespace
      {
    if (attrDescNoNSMap == null) this.attrDescNoNSMap = new MapLight<String, AttrDesc>(3);

    AttrDesc old = attrDescNoNSMap.put(attrDesc.getName(), attrDesc);
    if (old != null)
      throw new ItsNatDroidException(
          "Internal Error, duplicated attribute in this class or element: "
              + getClassOrDOMElemName()
              + " "
              + attrDesc.getName());
  }
コード例 #11
0
ファイル: ClassDesc.java プロジェクト: wodis/itsnat_droid
  protected <T extends AttrDesc> void addAttrDescAN(T attrDesc) // AN = Android Namespace
      {
    if (attrDescAndroidNSMap == null) this.attrDescAndroidNSMap = new HashMap<String, AttrDesc>();

    AttrDesc old = attrDescAndroidNSMap.put(attrDesc.getName(), attrDesc);
    if (old != null)
      throw new ItsNatDroidException(
          "Internal Error, duplicated attribute in this class or element: "
              + getClassOrDOMElemName()
              + " "
              + InflatedXML.XMLNS_ANDROID
              + " "
              + attrDesc.getName());
  }
 @Override
 public void redistributingExcessiveFractionOfVoteWeight(
     T winner, BigFraction excessiveFractionOfVoteWeight) {
   formatLine(
       "Es werden %f%% des Stimmgewichts von %s weiterverteilt.",
       excessiveFractionOfVoteWeight.percentageValue(), winner.getName());
 }
コード例 #13
0
ファイル: SalesSystemTableModel.java プロジェクト: tmev/Ants
 public boolean doesItemExist(final String name) {
   boolean bool = false;
   for (final T item : rows) {
     if (item.getName().equals(name)) bool = true;
   }
   return bool;
 }
コード例 #14
0
ファイル: SimpleTree.java プロジェクト: burgerm/molgenis
  /**
   * Construct a new Tree
   *
   * @param name unique name
   * @param parent the parent of this Tree. If null, then this is the root.
   */
  public SimpleTree(String name, T parent) {
    // System.out.println("SimpleTree name:" + name + "parent"+ parent);

    // checks
    if (StringUtils.isEmpty(name)) {
      throw new IllegalArgumentException("name cannot be empty");
    }
    if (parent != null)
      try {
        if (parent.get(name) != null)
          throw new IllegalArgumentException("elements already exists with name = '" + name + "'");
      } catch (NullPointerException e) {
        logger.error("NullPointer in constructor op SimpleTree", e);
      }

    // body
    this.name = name;
    if (parent == null) {
      // this is the root element of the tree, the map is ordered
      treeElements = new LinkedHashMap<String, T>();
    } else {
      treeElements = parent.getTreeElements(); // get a pointer to tree
      // elements.
      parentName = parent.getName();
    }
    treeElements.put(name, (T) this);
  }
コード例 #15
0
ファイル: MacRevised.java プロジェクト: rapodaca/cpsolver
 /** sets value to be good */
 protected void setGood(T value) {
   sLogger.debug("    -- set good " + value.variable().getName() + " = " + value.getName());
   Set<T> noGood = noGood(value);
   if (noGood != null) for (T v : noGood) removeSupport(v.variable(), value);
   value.setExtra(null);
   goodnessChanged(value);
 }
コード例 #16
0
  public TriggerPanel(TriggersPackage pak, T trigger) {
    super(new BorderLayout());

    this.pak = pak;
    this.trigger = trigger;

    this.tree_root = new DefaultMutableTreeNode(trigger.getName());
    this.group_events = new TriggerEventRoot();
    this.group_conditions = new TriggerConditionsRoot();
    this.group_actions = new TriggerActionRoot();
    this.tree_root.add(group_events);
    this.tree_root.add(group_conditions);
    this.tree_root.add(group_actions);

    this.tree_view = new TriggerTreeView();

    this.comment.setText(trigger.comment);

    split.setTopComponent(split_h);
    split.setBottomComponent(south_h);

    JScrollPane left = new JScrollPane(tree_view);
    left.setMinimumSize(new Dimension(200, 120));
    split_h.setLeftComponent(left);
    split_h.setRightComponent(new JScrollPane(comment));
    split_h.setMinimumSize(new Dimension(200, 160));

    tree_view.expandAll();

    this.add(split);
    super.addAncestorListener(this);
  }
コード例 #17
0
ファイル: Utils.java プロジェクト: fordream/dungeon
 /**
  * Finds matches of {@code Selectable}s based on a given {@code Collection} of objects and an
  * array of search tokens.
  *
  * @param collection a {@code Collection} of {@code Selectable} objects
  * @param complete if true, only elements that match all tokens are returned
  * @param tokens the search Strings
  * @param <T> a type T that extends {@code Selectable}
  * @return a {@code Matches} object with zero or more elements of type T
  */
 private static <T extends Selectable> Matches<T> findMatches(
     Collection<T> collection, boolean complete, String... tokens) {
   List<T> listOfMatches = new ArrayList<T>();
   // Do not start with 0, as this would gather all Articles if the query did not match any
   // Article.
   double maximumSimilarity = 1e-6;
   for (T candidate : collection) {
     String[] titleWords = split(candidate.getName().getSingular());
     int matches = countMatches(tokens, titleWords);
     if (!complete || matches >= tokens.length) {
       double matchesOverTitleWords = matches / (double) titleWords.length;
       double matchesOverSearchArgs = matches / (double) tokens.length;
       double similarity = DungeonMath.mean(matchesOverTitleWords, matchesOverSearchArgs);
       int comparisonResult = DungeonMath.fuzzyCompare(similarity, maximumSimilarity);
       if (comparisonResult > 0) {
         maximumSimilarity = similarity;
         listOfMatches.clear();
         listOfMatches.add(candidate);
       } else if (comparisonResult == 0) {
         listOfMatches.add(candidate);
       }
     }
   }
   return Matches.fromCollection(listOfMatches);
 }
コード例 #18
0
ファイル: FolderUtils.java プロジェクト: syncloud-old/core
 public static <T extends INode> T find(List<T> nodes, String searchFor) {
   for (T node : nodes) {
     String name = node.getName();
     if (name.equals(searchFor)) return node;
   }
   return null;
 }
コード例 #19
0
 @Test
 public final void
     givenResourceExists_whenSearchByStartsWithPartOfLowerCaseNameIsPerformed_thenResourceIsFound() {
   final T newEntity = createNewResource();
   SearchIntegrationTestUtil
       .givenResourceExists_whenSearchByStartsWithPartOfLowerCaseNameIsPerformed_thenResourceIsFound(
           getApi(), newEntity, SearchField.name, ClientOperation.ENDS_WITH, newEntity.getName());
 }
コード例 #20
0
 @Override
 @Test
 public final void givenResourceWithNameExists_whenResourceIsSearchedByName_thenNoExceptions() {
   final T existingResource = getApi().create(createNewResource());
   getApi()
       .searchAsResponse(
           null, ClientConstraintsUtil.createNameConstraint(EQ, existingResource.getName()));
 }
コード例 #21
0
ファイル: MacRevised.java プロジェクト: rapodaca/cpsolver
 public boolean revise(T value) {
   sLogger.debug("  -- revise " + value.variable().getName() + " = " + value.getName());
   for (Constraint<V, T> constraint : value.variable().hardConstraints()) {
     if (!contains(constraint)) continue;
     if (revise(constraint, value)) return true;
   }
   return false;
 }
  protected <T extends Site.Page> Page generateChild(
      Confluence confluence, T child, String spaceKey, String parentPageTitle, String titlePrefix) {

    java.net.URI source = child.getUri(getProject(), getFileExt());

    getLog()
        .info(
            String.format(
                "generateChild spacekey=[%s] parentPageTtile=[%s]\n%s",
                spaceKey, parentPageTitle, child.toString()));

    try {

      if (!isSnapshot() && isRemoveSnapshots()) {
        final String snapshot = titlePrefix.concat("-SNAPSHOT");
        boolean deleted =
            ConfluenceUtils.removePage(confluence, spaceKey, parentPageTitle, snapshot);

        if (deleted) {
          getLog().info(String.format("Page [%s] has been removed!", snapshot));
        }
      }

      final String pageName = String.format("%s - %s", titlePrefix, child.getName());

      Page p = ConfluenceUtils.getOrCreatePage(confluence, spaceKey, parentPageTitle, pageName);

      if (source != null /*&& source.isFile() && source.exists() */) {

        final MiniTemplator t =
            new MiniTemplator.Builder()
                .setSkipUndefinedVars(true)
                .build(Site.processUri(source), getCharset());

        addProperties(t);

        p.setContent(t.generateOutput());
      }

      p = confluence.storePage(p);

      for (String label : child.getComputedLabels()) {

        confluence.addLabelByName(label, Long.parseLong(p.getId()));
      }

      child.setName(pageName);

      return p;

    } catch (Exception e) {
      final String msg = "error loading template";
      getLog().error(msg, e);
      // throw new MavenReportException(msg, e);

      return null;
    }
  }
コード例 #23
0
 protected <T extends MaterialAvatar> void checkNameAndHashCode(T avatar) {
   final String NAME = "test1";
   avatar.setName(NAME);
   avatar.initialize();
   final String HASH_CODE = JsAvatar.md5(NAME);
   assertEquals(avatar.getName(), NAME);
   assertTrue(avatar.getElement().hasAttribute("data-jdenticon-hash"));
   assertEquals(avatar.getElement().getAttribute("data-jdenticon-hash"), HASH_CODE);
 }
コード例 #24
0
  /**
   * Returns a list of names ({@see cz.cuni.mff.ksi.jinfer.base.interfaces.NamedModule#getName()})
   * of all the implementations of requested interface registered via {@see
   * org.openide.util.lookup.ServiceProvider}.
   *
   * @param <T> Interface for which the names are to be found. Must extend NamedModule.
   * @param clazz Interface for which the names are to be found. Must extend NamedModule.
   * @return Alphabetically sorted list of all names of modules registered as {@see
   *     org.openide.util.lookup.ServiceProvider} implementing the requested interface.
   */
  public static <T extends NamedModule> List<String> lookupNames(final Class<T> clazz) {

    final List<String> ret = new ArrayList<String>();
    for (final T implementation : Lookup.getDefault().lookupAll(clazz)) {
      ret.add(implementation.getName());
    }
    Collections.sort(ret);
    return ret;
  }
コード例 #25
0
  public void forceInitialization() {
    if (!isInitialized()) {
      variables = new HashMap<String, T>();

      for (T variable : variablesProvider.provideVariables()) {
        variables.put(variable.getName(), variable);
      }
    }
  }
コード例 #26
0
ファイル: SalesSystemTableModel.java プロジェクト: tmev/Ants
 public String[] getProductNames() {
   String[] pikkus = new String[rows.size()];
   int i = 0;
   for (final T item : rows) {
     pikkus[i] = item.getName();
     i++;
   }
   return pikkus;
 }
コード例 #27
0
ファイル: BaseSetWrapper.java プロジェクト: yehecan/bw-util
  T find(final QName nm) {
    for (T t : els) {
      if (t.getName().equals(nm)) {
        return t;
      }
    }

    return null;
  }
コード例 #28
0
ファイル: BaseDao.java プロジェクト: winhell/newTemplate
 public void txUpdate(T entity, Person oper) {
   saveOrUpdate(entity);
   Syslog syslog = new Syslog();
   syslog.setUserid(oper.getName());
   syslog.setName(OperEnum.UPDATE.toString());
   syslog.setComment("用户" + oper.getName() + "修改" + className + "-->" + entity.getName());
   syslog.setCreatetime(Utils.getNow());
   syslog.setId(Utils.getNewUUID());
   getSession().save(syslog);
 }
コード例 #29
0
  /**
   * Add the table returning its index or -1 if rejected
   *
   * @param table
   * @param logger
   * @return
   */
  public int addTable(T table) {
    if (TableUtils.findTableIndex(this, table.getName(), true) != -1) {
      throw new RuntimeException("Table already exists: " + table.getName());
    }

    if (table.getImmutableId() == -1) {
      throw new RuntimeException("Invalid table immutable id in table: " + table.getName());
    }

    // we throw an exception if the id is already used because this will
    // be caused by a code error rather than a user error
    if (tablesById.get(table.getImmutableId()) != null) {
      throw new RuntimeException("Duplicate table id");
    }

    tablesByIndx.add(table);
    tablesById.put(table.getImmutableId(), table);
    return tablesByIndx.size() - 1;
  }
コード例 #30
0
ファイル: MacRevised.java プロジェクト: rapodaca/cpsolver
 private String expl2str(Set<T> expl) {
   StringBuffer sb = new StringBuffer("[");
   for (Iterator<T> i = expl.iterator(); i.hasNext(); ) {
     T value = i.next();
     sb.append(value.variable().getName() + "=" + value.getName());
     if (i.hasNext()) sb.append(", ");
   }
   sb.append("]");
   return sb.toString();
 }