constraints

Double generic constraint on class in Java: extends ConcreteClass & I

本秂侑毒 提交于 2019-12-04 02:54:50
Is there a way to define a generic constraint in Java which would be analogous to the following C# generic constratint ? class Class1<I,T> where I : Interface1, Class2 : I I'm trying to do it like this: class Class1<I extends Interface1, T extends I & Class2> But the compiler complains about the "Class2" part: Type parameter cannot be followed by other bounds. The simplest way I can see of resolving the Java code is to make Class2 an interface. You cannot constrain a type parameter to extends more than one class or type parameter. Further, you can't use super here. This code compiles here fine

Why does a Generic<T> method with a “where T : class” constraint accept an interface

喜欢而已 提交于 2019-12-04 02:53:06
问题 I have this interface : public interface ITestInterface { int TestInt { get; set; } } and this generic method (with a T : class constraint): public void Test<T>() where T : class { // DoSomething } and this call: Test<ITestInterface>(); and everything compiles and runs while an interface is not a class (or is it?). Why does this happen? I first saw this on my WCF proxy class: public partial class TestServiceClient: System.ServiceModel.ClientBase<TestNamespace.ITestService>, TestNamespace

An issue with Content Hugging and Content Compression Resistance, Autolayout Constraints

混江龙づ霸主 提交于 2019-12-04 02:13:29
问题 I have modified the question to be more information provided and clear. I wanted to have a dynamic table view cell, with a flexible height of UITextView and an optional UIImageView. Based on the content size of the UITextView and the optional UIImageView, the cell can be shrunk or extended. Here is what I expected to have (with the below picture): Normal size: height of TextView is fixed (say 77). ImageView width and height are also fixed (say 130, 130) When content size of TextView

How to convert n-ary CSP to binary CSP using dual graph transformation

蓝咒 提交于 2019-12-04 00:27:36
When I read the book -- Artificial Intelligence (a modern approach), I came across the following sentence describing the method to convert a n-ary Constraint Search Problem to a binary one: Another way to convert an n-ary CSP to a binary one is the dual graph transformation: create a new graph in which there will be one variable for each constraint in the original graph, and one binary constraint for each pair of constraints in the original graph that share variables. For example, if the original graph has variables {X, Y, Z} and constraints ⟨(X, Y, Z), C1⟩ and ⟨(X, Y ), C2⟩ then the dual

Access SQL to create one-to-many relation without Enforce Referential Integrity

扶醉桌前 提交于 2019-12-04 00:26:09
I have this relation. And I have to temporarily destroy it just to change the size of "salID" field using SQL command: ALTER TABLE Adressen DROP CONSTRAINT [ChildTableMainTable] How can I recreate the same relation type using SQL commands? If I use the next SQL I get a one to many relation. This is not what I need: ALTER TABLE MainTable ADD CONSTRAINT [ChildTableMainTable] FOREIGN KEY (salID) REFERENCES [ChildTable] (ChildPK); To the best of my knowledge, Access DDL simply does not support the creation of an Access "Relationship" without "Enforce Referential Integrity". CREATE CONSTRAINT will

add constraints programmatically swift

本小妞迷上赌 提交于 2019-12-04 00:17:59
I am trying to add constraints to a facebook sdk login button. I have the button inside a scroll view and I am trying to add a top constraint to a label that is also in the scroll view. I am able to successfully add the height constraint with no run time errors but the actual constraint does not seem to be applied to the button. @IBOutlet weak var orLbl: UILabel! @IBOutlet weak var scrollView: UIScrollView! override func viewDidLoad() { super.viewDidLoad() var loginFBButton = FBSDKLoginButton() loginFBButton.readPermissions = ["public_profile", "email"] let heightConstraint =

Laravel Eloquent truncate - Foreign key constraint

删除回忆录丶 提交于 2019-12-03 23:57:31
I am having some issues with deleting data using Laravel 5. I seem to be stuck on a 'foreign key constraint', while I don't see why. In my current database model I have a datapoints table, which has a foreign key to the sensors table (datapoints.sensors_id -> sensor.id). The code I am trying: Route::get('/truncateData', function() { DB::table('datapoints')->truncate(); DB::table('sensors')->truncate(); return 'Done...'; }); The result: SQLSTATE[42000]: Syntax error or access violation: 1701 Cannot truncate a table referenced in a foreign key constraint ( alerting . datapoints , CONSTRAINT

How scala generic constraints to nullable types work

心不动则不痛 提交于 2019-12-03 23:36:56
I've tried two ways to constrain a generic type parameter to a nullable type, but both seem to have some unexpected problems. First attempt (using T <: AnyRef): scala> def testAnyRefConstraint[T <: AnyRef](option:Option[T]):T = { | //without the cast, fails with compiler error: | // "found: Null(null) required: T" | option getOrElse null.asInstanceOf[T] | } testAnyRefConstraint: [T <: AnyRef](Option[T])T scala> testAnyRefConstraint(Some("")) res0: java.lang.String = scala> testAnyRefConstraint(Some(0)) <console>:16: error: inferred type arguments [Int] do not conform to method

Optimization in R with arbitrary constraints

孤街醉人 提交于 2019-12-03 22:47:39
I have done it in Excel but need to run a proper simulation in R. I need to minimize function F(x) ( x is a vector) while having constraints that sum(x)=1 , all values in x are [0,1] and another function G(x) > G_0 . I have tried it with optim and constrOptim . None of them give you this option. The problem you are referring to is (presumably) a non-linear optimization with non-linear constraints. This is one of the most general optimization problems. The package I have used for these purposes is called nloptr : see here . From my experience, it is both versatile and fast. You can specify both

How to add a not null constraint on column containing null values

痴心易碎 提交于 2019-12-03 22:25:05
I have a table with a column that contains a few null values. I want to add a NOT NULL constraint on that column without updating the existing nulls to a non-null value. I want to keep the existing null values and check for future rows that they contain a not null value for this column. Is this possible? How? You can add an unvalidated constraint - it will not look at existing rows, but it will be checked for any new or updated rows. ALTER TABLE mytable MODIFY mycolumn NOT NULL NOVALIDATE; Just be aware that you won't be able to update an existing row unless it satisfies the constraint. Also,