private static char isLocalStarGraph(final Traversal.Admin<?, ?> traversal, char state) { if (state == 'u' && (traversal instanceof ElementValueTraversal || (traversal instanceof TokenTraversal && !((TokenTraversal) traversal).getToken().equals(T.id)))) return 'x'; for (final Step step : traversal.getSteps()) {
public default ElementRequirement getMaxRequirement() { ElementRequirement max = ElementRequirement.ID; if (this instanceof TraversalParent) { for (final Traversal.Admin<Object, Object> traversal : ((TraversalParent) this).getLocalChildren()) { if (traversal instanceof IdentityTraversal) { if (max.compareTo(ElementRequirement.ID) < 0) max = ElementRequirement.ID; } else if (traversal instanceof TokenTraversal && ((TokenTraversal) traversal).getToken().equals(T.id)) { if (max.compareTo(ElementRequirement.ID) < 0) max = ElementRequirement.ID; } else if (traversal instanceof TokenTraversal && ((TokenTraversal) traversal).getToken().equals(T.label)) { if (max.compareTo(ElementRequirement.LABEL) < 0) max = ElementRequirement.LABEL; } else if (traversal instanceof ElementValueTraversal) { if (max.compareTo(ElementRequirement.PROPERTIES) < 0) max = ElementRequirement.PROPERTIES; } else { max = ElementRequirement.EDGES; } } } return max; }
public boolean remove(T item) { Iterator<T> iter = bag.iterator(); while (iter.hasNext()) { T i = iter.next(); if (i.equals(item)) { iter.remove(); return true; } } return false; }
for (Iterator<T> iterator = list.iterator(); iterator.hasNext(); ) { T element = iterator.next(); if (element.equals(elementToRemove)) { iterator.remove(); } }
ArrayList<T> matches = new ArrayList<T>; // T is your object type, e.g. String for (T item : myObjects) { if (item.equals(thingToMatch)) matches.add(item); }
Collection<T> ts; f(ts, new Predicate<T> () { public boolean test(T element) { return element.equals("foo"); } }); Collection<P> ps; f(ps, new Predicate<P> () { public boolean test(P element) { return element.getT().equals("foo"); } });
public T remove(T elt) { for (int i=0; i<data.length; ++i) { if (elt.equals(data[i]) ) { data[i] = null; for (++i; i < data.length; ++i) { data[i-1] = data[i]; } break; } }
public boolean contain(T o) { if (o == null) { // assuming that your list accept to add null object for (Node<T> x = first; x != null; x = x.next) { if (x.data == null) return true; } } else { for (Node<T> x = first; x != null; x = x.next) { if (o.equals(x.data)) return true; } } return false; }
public int getPosition(T anObject) { int position = 0; Node currentNode = firstNode; while(currentNode != null) { if(anObject.equals(currentNode.data)) { break; // we found our node so we can stop searching } position++; currentNode = currentNode.next; } // we iterated through the whole list and didn't find the node if(currentNode == null) { return -1; // or some other error value } return position; }
public LinkedList<T> toSet() { LinkedList<T> retList; retList = lista; Iterator<T> iter1 = retList.iterator(); int index1 = 0; while (iter1.hasNext()) { T elem1 = iter1.next(); Iterator<T> iter2 = retList.iterator(); int index2 = 0; while (iter2.hasNext()) { T elem2 = iter2.next(); if(index1 != index2 && elem1.equals(elem2)) iter2.remove(); index2++; } index1++; } return retList; }
public iterator search(T data) { no<T> temp = first; while (!data.equals(temp.data)) { temp = temp.next; } return (new iterator(temp)); }
public BagInterface<T> union(T[] item) { List<T> unionList = Arrays.asList(this.bag); for(T elem: item){ boolean present = false; for(T elem1: this.bag){ if(elem1.equals(elem)){ present = true; } } if(!present){ unionList.add(elem); } } this.bag = unionList.toArray(new Bag[unionList.size()]); return this; }
public BinarySearchTreeNode<T> getParent(BinarySearchTreeNode<T> e) { if (e == null) { return null; } BinarySearchTreeNode<T> current = this.root; T eValue = e.getValue(); while (current != null) { if (howManyChildren(current) == 0) { return null; } else if ((current.getLeft()!=null && eValue.equals(current.getLeft().getValue())) || (current.getRight()!=null) && eValue.equals(current.getRight().getValue())) { return current; } else if (eValue.compareTo(current.getValue()) < 0) { current = current.getLeft(); } else { current = current.getRight(); } } return null; }
public void compareLists(final List<T> allProcesses, final List<T> runningProcesses) { // Assume lists are sorted, if not call Collection.sort() on each list (making this O(nlogn)) final Iterator<T> allIter = allProcesses.iterator(); final Iterator<T> runningIter = runningProcesses.iterator(); T allEntry; T runningEntry; while (allIter.hasNext() && runningIter.hasNext()) { allEntry = allIter.next(); runningEntry = runningIter.next(); while (!allEntry.equals(runningEntry) && allIter.hasNext()) { System.out.println(allEntry); allEntry = allIter.next(); } // Now we know allEntry == runningEntry, so we can go through to the next iteration } // No more running processes, so just print the remaining entries in the all processes list while (allIter.hasNext()) { System.out.println(allIter.next()); } }
Map<T, Integer> rankMap = new HashMap<>(coll.size()); int rank = 0; for (T t : coll) rankMap.put(t, t.equals(first) ? -1 : rank++); Comparator<T> cmp = Comparator.comparing(rankMap::get);
private boolean isProperty(Entry<?, ?> e, boolean gremlinTokensCanBeMapKeys) { if (gremlinTokensCanBeMapKeys) { return !T.id.equals(e.getKey()) && !T.label.equals(e.getKey()); } else { return !("label".equals(e.getKey()) && !isVertexValueList(e.getValue())) && !("id".equals(e.getKey()) && !isVertexValueList(e.getValue())); } } }
public static void main(String[] args) { foo Foo = new foo(); System.out.println(Foo.compare(100L, 100)); System.out.println(Foo.compare(100L, 100L)); System.out.println(Foo.compare(127L, 127L)); System.out.println(Foo.compare(128L, 128L)); System.out.println(); System.out.println(System.getProperty("java.vendor")); System.out.println(System.getProperty("java.version")); } public boolean compare( T val1, T val2) { return ( val1.equals(val2) ) ? true : false; // use equal instead }
@Override public void commitEdit(T item) { // This block is necessary to support commit on losing focus, because the baked-in mechanism // sets our editing state to false before we can intercept the loss of focus. // The default commitEdit(...) method simply bails if we are not editing... if (! isEditing() && ! item.equals(getItem())) { TableView<S> table = getTableView(); if (table != null) { TableColumn<S, T> column = getTableColumn(); CellEditEvent<S, T> event = new CellEditEvent<>(table, new TablePosition<S,T>(table, getIndex(), column), TableColumn.editCommitEvent(), item); Event.fireEvent(column, event); } } super.commitEdit(item); }
private int binarySearchRecursive(int first, int last, T desiredItem) { int position = 0; int mid = (first + last) / 2; if (first > last) position = -(last + 1); else if (desiredItem.equals(list[mid])) position = mid; else if (desiredItem.compareTo(list[mid]) < 0) position = binarySearchRecursive(first, mid -1, desiredItem); else position = binarySearchRecursive(mid + 1, last, desiredItem); return position; }
@Override public <U> Property<U> property(String key, U value) { if (T.id.equals(key)) throw VertexProperty.Exceptions.userSuppliedIdsNotSupported(); ODocument metadata = getMetadataDocument(); metadata.field(key, value); return new OrientVertexPropertyProperty<>(key, value, this); }