Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PeriodSum tests and implementation #10

Merged
merged 1 commit into from
Mar 8, 2016
Merged

Conversation

awmarkley
Copy link
Collaborator

Implements PeriodSums with functionality for PeriodSums that contain SimplePeriods and PeriodSums

override def subtractFrom(temporal: Temporal): Temporal = ???
for ( period <- periods; unit <- period.getUnits.asScala )
map.get(unit) match {
case Some(value) => map.update( unit, value + period.get(unit))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, that was my initial attempt, but I had to use the match keyword because there is nothing present in the map when it is instantiated, the map throws a NoSuchElementException because the key that we are trying to access has not been added yet.

Or do you mean line 80 specifically?

@awmarkley
Copy link
Collaborator Author

Corrected for PR comments

for ( period <- periods; unit <- period.getUnits.asScala )
map.get(unit) match {
case Some(value) => map(unit) += period.get(unit)
case None => map += (unit -> period.get(unit))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, should have caught this on my last pass. You can write this as map(unit) = period.get(unit).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scala doesn't seem to like that method of expressing the assignment, I get an error reading "Expression of type Long doesn't conform to expected type mutable.Map[TemporalUnit, Long]"

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to work okay for me:

scala> var map = scala.collection.mutable.Map.empty[String, Long]
map: scala.collection.mutable.Map[String,Long] = Map()
scala> map("a") = 5
scala> map
res1: scala.collection.mutable.Map[String,Long] = Map(a -> 5)

@awmarkley
Copy link
Collaborator Author

I have no idea why it would not let me compile with that expression before - it should be fixed now!

bethard added a commit that referenced this pull request Mar 8, 2016
PeriodSum tests and implementation
@bethard bethard merged commit 219901f into clulab:master Mar 8, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants