/** * create group head Object, default implementation return first element of groupdata. you can * override this method to return your Object. * * @param groupdata data the already in a group. * @param index group index * @param col column to group */ @SuppressWarnings("unchecked") protected H createGroupHead(D[] groupdata, int index, int col) { final D o = groupdata[0]; return o != null && o.getClass().isArray() && col < Array.getLength(o) ? (H) Array.get(o, col) : (H) o; }
public void testInit() throws Exception { ComponentDef cd = new ComponentDefImpl(D.class); cd.addInitMethodDef(new InitMethodDefImpl("init")); cd.init(); D d = (D) cd.getComponent(); assertEquals("1", true, d.isInited()); }
public void testDestroy() throws Exception { ComponentDef cd = new ComponentDefImpl(D.class); cd.addDestroyMethodDef(new DestroyMethodDefImpl("destroy")); D d = (D) cd.getComponent(); cd.destroy(); assertEquals("1", true, d.isDestroyed()); }
@Override public final D scan(I container, String path, Scope scope, Scanner scanner) throws IOException { ScannerContext context = scanner.getContext(); D containerDescriptor = getContainerDescriptor(container, context); String containerPath = getContainerPath(container, path); containerDescriptor.setFileName(containerPath); LOGGER.info("Entering {}", containerPath); ContainerFileResolver fileResolverStrategy = new ContainerFileResolver(containerDescriptor); context.push(FileResolver.class, fileResolverStrategy); enterContainer(container, containerDescriptor, scanner.getContext()); Stopwatch stopwatch = Stopwatch.createStarted(); try { Iterable<? extends E> entries = getEntries(container); for (E entry : entries) { String relativePath = getRelativePath(container, entry); try (Resource resource = getEntry(container, entry)) { LOGGER.debug("Scanning {}", relativePath); FileDescriptor descriptor = scanner.scan(resource, relativePath, scope); fileResolverStrategy.put(relativePath, descriptor); } } } finally { leaveContainer(container, containerDescriptor, scanner.getContext()); context.pop(FileResolver.class); } fileResolverStrategy.flush(); LOGGER.info( "Leaving {} ({} entries, {} ms)", containerPath, fileResolverStrategy.size(), stopwatch.elapsed(MILLISECONDS)); return containerDescriptor; }
@Override public boolean equals(final Object obj) { if (this == obj) { return true; } if (!Association.class.isInstance(obj)) { return false; } try { @SuppressWarnings("unchecked") Association<K, L, A, M, D> other = (Association<K, L, A, M, D>) obj; A other_a = other.getAntecendent(); A this_a = this.getAntecendent(); if (this_a == other_a || (this_a != null && this_a.equals(other_a))) { D other_d = other.getDependent(); D this_d = this.getDependent(); if (this_d == other_d || (this_d != null && this_d.equals(other_d))) { return true; } } } catch (ClassCastException ex) { return false; } return false; }
/** * Runs a canny edge detector on the input image given the provided thresholds. If configured to * save a list of trace points then the output image is optional. * * <p>NOTE: Input and output can be the same instance, if the image type allows it. * * @param input Input image. Not modified. * @param threshLow Lower threshold. >= 0. * @param threshHigh Upper threshold. >= 0. * @param output (Might be option) Output binary image. Edge pixels are marked with 1 and * everything else 0. */ public void process(T input, float threshLow, float threshHigh, ImageUInt8 output) { if (threshLow < 0 || threshHigh < 0) throw new IllegalArgumentException("Threshold must be >= zero!"); if (hysteresisMark != null) { if (output == null) throw new IllegalArgumentException( "An output image must be specified when configured to mark edge points"); } // setup internal data structures blurred.reshape(input.width, input.height); derivX.reshape(input.width, input.height); derivY.reshape(input.width, input.height); intensity.reshape(input.width, input.height); suppressed.reshape(input.width, input.height); angle.reshape(input.width, input.height); direction.reshape(input.width, input.height); work.reshape(input.width, input.height); // run canny edge detector blur.process(input, blurred); gradient.process(blurred, derivX, derivY); GGradientToEdgeFeatures.intensityAbs(derivX, derivY, intensity); GGradientToEdgeFeatures.direction(derivX, derivY, angle); GradientToEdgeFeatures.discretizeDirection4(angle, direction); GradientToEdgeFeatures.nonMaxSuppression4(intensity, direction, suppressed); performThresholding(threshLow, threshHigh, output); }
@Override public boolean equals(Object obj) { if (NativeTypeVariableEquals.NATIVE_TYPE_VARIABLE_ONLY) { // equal only to our TypeVariable implementation with identical bounds if (obj != null && Proxy.isProxyClass(obj.getClass()) && Proxy.getInvocationHandler(obj) instanceof TypeVariableInvocationHandler) { TypeVariableInvocationHandler typeVariableInvocationHandler = (TypeVariableInvocationHandler) Proxy.getInvocationHandler(obj); TypeVariableImpl<?> that = typeVariableInvocationHandler.typeVariableImpl; return name.equals(that.getName()) && genericDeclaration.equals(that.getGenericDeclaration()) && bounds.equals(that.bounds); } return false; } else { // equal to any TypeVariable implementation regardless of bounds if (obj instanceof TypeVariable) { TypeVariable<?> that = (TypeVariable<?>) obj; return name.equals(that.getName()) && genericDeclaration.equals(that.getGenericDeclaration()); } return false; } }
/** * This method simulate the normal write procedure in SSD device * * @param device - the device to write on * @param lp -logical page to write * @return the device after the write */ @SuppressWarnings("unchecked") public D writeLP(D device, int lp, int arg) { D cleanDevice = (D) device.invokeCleaning(); cleanDevice = (D) cleanDevice.invalidate(lp); cleanDevice = (D) cleanDevice.writeLP(lp, arg); return cleanDevice; }
@Override public String toString() { if (d instanceof SingleDie) { return nb + d.toString(); } else { return nb + "(" + d.toString() + ")"; } }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((edgeLabel == null) ? 0 : edgeLabel.hashCode()); result = prime * result + ((endNode == null) ? 0 : endNode.hashCode()); result = prime * result + ((startNode == null) ? 0 : startNode.hashCode()); return result; }
protected String[] getExportColumns() { return new String[] { dao.getPrimaryKeyColumnName(), dao.getCreatedDateColumnName(), dao.getCreatedByColumnName(), dao.getUpdatedDateColumnName(), dao.getUpdatedByColumnName() }; }
/** * {@inheritDoc} * * @see net.sf.hajdbc.distributed.Stateful#writeState(java.io.ObjectOutput) */ @Override public void writeState(ObjectOutput output) throws IOException { Set<D> databases = this.cluster.getBalancer(); output.writeInt(databases.size()); for (D database : databases) { output.writeUTF(database.getId()); } }
@Override public D save(D definition) { Assert.notNull(definition, "Definition may not be null"); if (repository.findOne(definition.getName()) != null) { throwDefinitionAlreadyExistsException(definition); } streamParser.parse(definition.getName(), definition.getDefinition()); return repository.save(definition); }
public <S, P, R, D extends Pda<S, P>> D filterEdges( Pda<S, P> pda, Traverser<? super Pda<S, P>, S, R> traverser, PdaFactory<D, S, P, S> factory) { HashStack<TraversalItem<S, R>> trace = new HashStack<TraversalItem<S, R>>(); R previous = traverser.enter(pda, pda.getStart(), null); if (previous == null) return factory == null ? null : factory.create(pda.getStart(), pda.getStop()); Map<S, Integer> distances = new NfaUtil().distanceToFinalStateMap(pda); MappedComparator<S, Integer> distanceComp = new MappedComparator<S, Integer>(distances); trace.push(newItem(pda, distanceComp, distances, pda.getStart(), previous)); Multimap<S, S> edges = LinkedHashMultimap.create(); HashSet<S> states = Sets.newLinkedHashSet(); HashSet<Pair<S, R>> success = Sets.newLinkedHashSet(); states.add(pda.getStart()); states.add(pda.getStop()); ROOT: while (!trace.isEmpty()) { TraversalItem<S, R> current = trace.peek(); while (current.followers.hasNext()) { S next = current.followers.next(); R item = traverser.enter(pda, next, current.data); if (item != null) { if ((next == pda.getStop() && traverser.isSolution(item)) || success.contains(Tuples.create(next, item))) { S s = null; for (TraversalItem<S, R> i : trace) { if (s != null) edges.put(s, i.state); states.add(i.state); success.add(Tuples.create(i.state, i.data)); s = i.state; } edges.put(s, next); } else { if (trace.push(newItem(pda, distanceComp, distances, next, item))) continue ROOT; } } } trace.pop(); } if (factory == null) return null; D result = factory.create(pda.getStart(), pda.getStop()); Map<S, S> old2new = Maps.newLinkedHashMap(); old2new.put(pda.getStart(), result.getStart()); old2new.put(pda.getStop(), result.getStop()); for (S old : states) { if (old == pda.getStart() || old == pda.getStop()) continue; else if (pda.getPop(old) != null) old2new.put(old, factory.createPop(result, old)); else if (pda.getPush(old) != null) old2new.put(old, factory.createPush(result, old)); else old2new.put(old, factory.createState(result, old)); } for (S old : states) { List<S> followers = Lists.newArrayList(); for (S f : edges.get(old)) followers.add(old2new.get(f)); factory.setFollowers(result, old2new.get(old), followers); } return result; }
/** * 保存数据(插入或更新) * * @param entity */ @Transactional(readOnly = false) public void save(T entity) { if (entity.getIsNewRecord()) { entity.preInsert(); dao.insert(entity); } else { entity.preUpdate(); dao.update(entity); } }
public static void main(String[] args) { D.println("Should be false: " + contains(Object.class, "frob1")); put(Object.class, "frob1"); put(ClassObjectFilter.class, "frob2"); D.println("Should be false: " + contains(ClassObjectFilter.class, "frob1")); D.println("Should be true: " + contains(ClassObjectFilter.class, "frob2")); D.println("Should be true: " + contains(Object.class, "frob1")); put(Object.class, "frob2"); D.println("Should be true: " + contains(Object.class, "frob2")); }
@Override public Map<String, Class> getTypeMap() { final TreeMap<String, Class> map = new TreeMap<String, Class>(); for (String col : dao.getColumnNames()) { map.put(col, dao.getColumnClass(col)); } return map; }
public <D extends AbstractDisplayer> D initDisplayer(D displayer, DisplayerSettings settings) { displayer.setEvaluator(new DisplayerEvaluatorMock()); displayer.setFormatter(new DisplayerFormatterMock()); if (settings != null) { displayer.setDisplayerSettings(settings); displayer.setDataSetHandler( new DataSetHandlerImpl(clientServices, settings.getDataSetLookup())); } return displayer; }
/** * Provides basic un-deployment behavior, whereby state of deployed definitions is not dealt with. */ protected void basicUndeploy(String name) { D definition = getDefinitionRepository().findOne(name); if (definition == null) { throwNoSuchDefinitionException(name); } List<ModuleDeploymentRequest> requests = parse(name, definition.getDefinition()); for (ModuleDeploymentRequest request : requests) { request.setRemove(true); } Collections.reverse(requests); sendDeploymentRequests(name, requests); }
/** * Provides basic deployment behavior, whereby running state of deployed definitions is not * persisted. * * @return the definition object for the given name * @throws NoSuchDefinitionException if there is no definition by the given name */ protected D basicDeploy(String name) { Assert.hasText(name, "name cannot be blank or null"); final D definition = getDefinitionRepository().findOne(name); if (definition == null) { throwNoSuchDefinitionException(name); } final List<ModuleDeploymentRequest> requests = parse(name, definition.getDefinition()); sendDeploymentRequests(name, requests); return definition; }
static final <D extends Definition> D getDefinition( List<D> definitions, String name, boolean ignoreCase) { for (D definition : definitions) { if ((ignoreCase && definition.getName().equalsIgnoreCase(name)) || (!ignoreCase && definition.getName().equals(name))) { return definition; } } return null; }
private void updateObservedObjects() { for (Enumeration en = _observedObjects.elements(); en.hasMoreElements(); ) { FlexoModelObject observed = (FlexoModelObject) en.nextElement(); observed.deleteObserver(this); } _observedObjects.clear(); for (int i = 0; i < getRowCount(); i++) { D observed = elementAt(i); _observedObjects.add(observed); observed.addObserver(this); } }
/** * 保存数据(插入或更新) * * @param entity */ @Transactional(readOnly = false) public void save(T entity) { IInitCallback callback = new InitCallbackImpl(); if (entity.getIsNewRecord()) { entity.preInsert(callback); dao.insert(entity); } else { entity.preUpdate(callback); dao.update(entity); } }
@Override public List<ID> upsert(Iterable<T> dEntities) { final TransactionStatus transactionStatus = getTransaction(); // group entities by create or update: final ArrayList<T> toCreate = new ArrayList<T>(); final ArrayList<T> toUpdate = new ArrayList<T>(); ID id; for (T d : dEntities) { id = dao.getSimpleKey(d); if (null == id) { toCreate.add(d); } else { toUpdate.add(d); } } LOG.debug("Creating {}, Updating {}", toCreate.size(), toUpdate.size()); LOG.debug("Creating {}, Updating {}", toCreate, toUpdate); try { // create new entities using async API Future<List<?>> createFuture = null; if (!toCreate.isEmpty()) { createFuture = dao.persistForFuture(toCreate); } // update in parallel if (!toUpdate.isEmpty()) { dao.update(toUpdate); } // join future if (null != createFuture) { Collection<ID> ids = dao.getSimpleKeys(createFuture); // Iterator<ID> i = ids.iterator(); // for (T t : toCreate) { // dao.setSimpleKey(t, i.next()); // } } // collect the IDs final ArrayList<ID> body = new ArrayList<ID>(); for (T d : dEntities) { body.add(getSimpleKey(d)); } commitTransaction(transactionStatus); return body; } finally { rollbackTransaction(transactionStatus); } }
/** * Returns root and embedded devices registered under the given UDN. * * @param udn A unique device name. * @param rootOnly Set to true if only root devices (no embedded) should be searched * @return Any registered root or embedded device under the given UDN, <tt>null</tt> if no device * with the given UDN has been registered. */ D get(UDN udn, boolean rootOnly) { for (RegistryItem<UDN, D> item : deviceItems) { D device = item.getItem(); if (device.getIdentity().getUdn().equals(udn)) { return device; } if (!rootOnly) { D foundDevice = (D) item.getItem().findDevice(udn); if (foundDevice != null) return foundDevice; } } return null; }
@Override public int hashCode() { final int prime = 37; int result = 17; A a = getAntecendent(); result = prime * result + ((a == null) ? 0 : a.hashCode()); D d = getDependent(); result = prime * result + ((d == null) ? 0 : d.hashCode()); return result; }
@Override public void delete(String parentKeyString, ID id) { final TransactionStatus transactionStatus = getTransaction(); preDao(); try { Object parentKey = dao.getPrimaryKey(parentKeyString); dao.delete(parentKey, id); commitTransaction(transactionStatus); } finally { postDao(); rollbackTransaction(transactionStatus); } }
/** * Given a fake override, finds any declaration of it in the overridden descriptors. Keep in mind * that there may be many declarations of the fake override in the supertypes, this method finds * just the only one. TODO: probably all call-sites of this method are wrong, they should handle * all super-declarations */ @NotNull @SuppressWarnings("unchecked") public static <D extends CallableMemberDescriptor> D unwrapFakeOverride(@NotNull D descriptor) { while (descriptor.getKind() == CallableMemberDescriptor.Kind.FAKE_OVERRIDE) { Collection<? extends CallableMemberDescriptor> overridden = descriptor.getOverriddenDescriptors(); if (overridden.isEmpty()) { throw new IllegalStateException( "Fake override should have at least one overridden descriptor: " + descriptor); } descriptor = (D) overridden.iterator().next(); } return descriptor; }
@Test @TestForIssue(jiraKey = "HHH-5472") public void testCascade() { A a = new A(); B b = new B(); C c = new C(); D d = new D(); E e = new E(); F f = new F(); G g = new G(); H h = new H(); a.getBCollection().add(b); b.setA(a); a.getCCollection().add(c); c.setA(a); b.getCCollection().add(c); c.setB(b); a.getDCollection().add(d); d.getACollection().add(a); d.getECollection().add(e); e.setF(f); f.getBCollection().add(b); b.setF(f); c.setG(g); g.getCCollection().add(c); f.setH(h); h.setG(g); Session s; s = openSession(); s.getTransaction().begin(); try { // Fails: says that C.b is null (even though it isn't). Doesn't fail if you persist c, g or h // instead of a s.persist(a); s.flush(); } finally { s.getTransaction().rollback(); s.close(); } }
protected <S, P, T, D extends Pda<S, P>> S clone( S state, Pda<S, P> src, D target, Function<S, T> tokens, PdaFactory<D, S, P, T> fact, Identity<S> identity) { if (state == src.getStart()) return target.getStart(); if (state == src.getStop()) return target.getStop(); P push = src.getPush(state); if (push != null) return identity.get(fact.createPush(target, tokens.apply(state))); P pop = src.getPop(state); if (pop != null) return identity.get(fact.createPop(target, tokens.apply(state))); return identity.get(fact.createState(target, tokens.apply(state))); }