repo_name
stringlengths 7
104
| file_path
stringlengths 13
198
| context
stringlengths 67
7.15k
| import_statement
stringlengths 16
4.43k
| code
stringlengths 40
6.98k
| prompt
stringlengths 227
8.27k
| next_line
stringlengths 8
795
|
---|---|---|---|---|---|---|
trivago/Mail-Pigeon | pigeon-web/src/main/java/com/trivago/mail/pigeon/web/components/wizard/setup/steps/WizardAddRecipientGroupComponent.java | // Path: pigeon-common/src/main/java/com/trivago/mail/pigeon/bean/RecipientGroup.java
// public class RecipientGroup extends AbstractBean
// {
// public static final String ID = "group_id";
//
// public static final String NAME = "name";
//
// public static final String DATE = "date";
//
// public RecipientGroup(final Node underlayingNode)
// {
// this.dataNode = underlayingNode;
// }
//
// public RecipientGroup(final long groupId)
// {
// dataNode = ConnectionFactory.getGroupIndex().get(IndexTypes.GROUP_ID, groupId).getSingle();
// if (dataNode == null)
// {
// Transaction tx = ConnectionFactory.getDatabase().beginTx();
// try
// {
// dataNode = ConnectionFactory.getDatabase().createNode();
// writeProperty(ID, groupId);
// writeProperty("type", getClass().getName());
// writeProperty(NAME, "DefaultGroup");
// ConnectionFactory.getGroupIndex().add(this.dataNode, IndexTypes.GROUP_ID, groupId);
// ConnectionFactory.getGroupIndex().add(this.dataNode, IndexTypes.TYPE, getClass().getName());
// ConnectionFactory.getDatabase().getReferenceNode().createRelationshipTo(dataNode, RelationTypes.GROUP_REFERENCE);
//
// tx.success();
// }
// catch (Exception e)
// {
// log.error(e);
// tx.failure();
// }
// finally
// {
// tx.finish();
// }
// }
// }
//
// public RecipientGroup(final long groupId, final String name)
// {
// Transaction tx = ConnectionFactory.getDatabase().beginTx();
// try
// {
// dataNode = ConnectionFactory.getDatabase().createNode();
// writeProperty(ID, groupId);
// writeProperty("type", getClass().getName());
// writeProperty(NAME, name);
// ConnectionFactory.getGroupIndex().add(this.dataNode, IndexTypes.GROUP_ID, groupId);
// ConnectionFactory.getGroupIndex().add(this.dataNode, IndexTypes.TYPE, getClass().getName());
// ConnectionFactory.getDatabase().getReferenceNode().createRelationshipTo(dataNode, RelationTypes.GROUP_REFERENCE);
//
// tx.success();
// }
// catch (Exception e)
// {
// log.error(e);
// tx.failure();
// }
// finally
// {
// tx.finish();
// }
//
// }
//
// public Node getDataNode()
// {
// return dataNode;
// }
//
// public long getId()
// {
// return getProperty(Long.class, ID, false);
// }
//
// public String getName()
// {
// return getProperty(String.class, NAME);
// }
//
// public Relationship addRecipient(Recipient recipient)
// {
// Transaction tx = ConnectionFactory.getDatabase().beginTx();
// Relationship relation = null;
// try
// {
// Node recipientNode = recipient.getDataNode();
// relation = dataNode.createRelationshipTo(recipientNode, RelationTypes.BELONGS_TO_GROUP);
// relation.setProperty(DATE, new Date().getTime());
// tx.success();
//
// }
// catch (Exception e)
// {
// log.error(e);
// tx.failure();
// }
// finally
// {
// tx.finish();
// }
// return relation;
// }
//
// public Iterable<Relationship> getRecipients()
// {
// return dataNode.getRelationships(RelationTypes.BELONGS_TO_GROUP);
// }
//
// public static IndexHits<Node> getAll()
// {
// return ConnectionFactory.getGroupIndex().get("type", RecipientGroup.class.getName());
// }
//
// public void setName(String name)
// {
// writeProperty(NAME, name);
// }
// }
| import com.trivago.mail.pigeon.bean.RecipientGroup;
import com.vaadin.terminal.UserError;
import com.vaadin.ui.*;
import org.vaadin.teemu.wizards.WizardStep;
import java.util.Date; | + "You need a Recipient Group in order to send a Newsletter.</p>", Label.CONTENT_XHTML);
Panel rootPanel = new Panel("Add new group");
final VerticalLayout verticalLayout = new VerticalLayout();
tfName = new TextField("Name");
verticalLayout.addComponent(label);
verticalLayout.addComponent(tfName);
rootPanel.addComponent(verticalLayout);
return rootPanel;
}
@Override
public boolean onAdvance()
{
if (tfName.getValue().equals(""))
{
tfName.setComponentError(new UserError("Name must not be empty"));
}
else
{
tfName.setComponentError(null);
}
if (!tfName.getValue().equals(""))
{
tfName.setComponentError(null);
long grou_id = Math.round(new Date().getTime() * Math.random());
try
{ | // Path: pigeon-common/src/main/java/com/trivago/mail/pigeon/bean/RecipientGroup.java
// public class RecipientGroup extends AbstractBean
// {
// public static final String ID = "group_id";
//
// public static final String NAME = "name";
//
// public static final String DATE = "date";
//
// public RecipientGroup(final Node underlayingNode)
// {
// this.dataNode = underlayingNode;
// }
//
// public RecipientGroup(final long groupId)
// {
// dataNode = ConnectionFactory.getGroupIndex().get(IndexTypes.GROUP_ID, groupId).getSingle();
// if (dataNode == null)
// {
// Transaction tx = ConnectionFactory.getDatabase().beginTx();
// try
// {
// dataNode = ConnectionFactory.getDatabase().createNode();
// writeProperty(ID, groupId);
// writeProperty("type", getClass().getName());
// writeProperty(NAME, "DefaultGroup");
// ConnectionFactory.getGroupIndex().add(this.dataNode, IndexTypes.GROUP_ID, groupId);
// ConnectionFactory.getGroupIndex().add(this.dataNode, IndexTypes.TYPE, getClass().getName());
// ConnectionFactory.getDatabase().getReferenceNode().createRelationshipTo(dataNode, RelationTypes.GROUP_REFERENCE);
//
// tx.success();
// }
// catch (Exception e)
// {
// log.error(e);
// tx.failure();
// }
// finally
// {
// tx.finish();
// }
// }
// }
//
// public RecipientGroup(final long groupId, final String name)
// {
// Transaction tx = ConnectionFactory.getDatabase().beginTx();
// try
// {
// dataNode = ConnectionFactory.getDatabase().createNode();
// writeProperty(ID, groupId);
// writeProperty("type", getClass().getName());
// writeProperty(NAME, name);
// ConnectionFactory.getGroupIndex().add(this.dataNode, IndexTypes.GROUP_ID, groupId);
// ConnectionFactory.getGroupIndex().add(this.dataNode, IndexTypes.TYPE, getClass().getName());
// ConnectionFactory.getDatabase().getReferenceNode().createRelationshipTo(dataNode, RelationTypes.GROUP_REFERENCE);
//
// tx.success();
// }
// catch (Exception e)
// {
// log.error(e);
// tx.failure();
// }
// finally
// {
// tx.finish();
// }
//
// }
//
// public Node getDataNode()
// {
// return dataNode;
// }
//
// public long getId()
// {
// return getProperty(Long.class, ID, false);
// }
//
// public String getName()
// {
// return getProperty(String.class, NAME);
// }
//
// public Relationship addRecipient(Recipient recipient)
// {
// Transaction tx = ConnectionFactory.getDatabase().beginTx();
// Relationship relation = null;
// try
// {
// Node recipientNode = recipient.getDataNode();
// relation = dataNode.createRelationshipTo(recipientNode, RelationTypes.BELONGS_TO_GROUP);
// relation.setProperty(DATE, new Date().getTime());
// tx.success();
//
// }
// catch (Exception e)
// {
// log.error(e);
// tx.failure();
// }
// finally
// {
// tx.finish();
// }
// return relation;
// }
//
// public Iterable<Relationship> getRecipients()
// {
// return dataNode.getRelationships(RelationTypes.BELONGS_TO_GROUP);
// }
//
// public static IndexHits<Node> getAll()
// {
// return ConnectionFactory.getGroupIndex().get("type", RecipientGroup.class.getName());
// }
//
// public void setName(String name)
// {
// writeProperty(NAME, name);
// }
// }
// Path: pigeon-web/src/main/java/com/trivago/mail/pigeon/web/components/wizard/setup/steps/WizardAddRecipientGroupComponent.java
import com.trivago.mail.pigeon.bean.RecipientGroup;
import com.vaadin.terminal.UserError;
import com.vaadin.ui.*;
import org.vaadin.teemu.wizards.WizardStep;
import java.util.Date;
+ "You need a Recipient Group in order to send a Newsletter.</p>", Label.CONTENT_XHTML);
Panel rootPanel = new Panel("Add new group");
final VerticalLayout verticalLayout = new VerticalLayout();
tfName = new TextField("Name");
verticalLayout.addComponent(label);
verticalLayout.addComponent(tfName);
rootPanel.addComponent(verticalLayout);
return rootPanel;
}
@Override
public boolean onAdvance()
{
if (tfName.getValue().equals(""))
{
tfName.setComponentError(new UserError("Name must not be empty"));
}
else
{
tfName.setComponentError(null);
}
if (!tfName.getValue().equals(""))
{
tfName.setComponentError(null);
long grou_id = Math.round(new Date().getTime() * Math.random());
try
{ | RecipientGroup g = new RecipientGroup(grou_id, tfName.getValue().toString()); |
trivago/Mail-Pigeon | pigeon-web/src/main/java/com/trivago/mail/pigeon/web/components/sender/SenderList.java | // Path: pigeon-common/src/main/java/com/trivago/mail/pigeon/bean/Sender.java
// public class Sender extends AbstractBean
// {
// public static final String ID = "sender_id";
//
// public static final String NAME = "name";
//
// public static final String FROM_MAIL = "from_mail";
//
// public static final String REPLYTO_MAIL = "reply_to_mail";
//
// public Sender(final Node underlayingNode)
// {
// this.dataNode = underlayingNode;
// }
//
// public Sender(final long senderId)
// {
// dataNode = ConnectionFactory.getSenderIndex().get(IndexTypes.SENDER_ID, senderId).getSingle();
// }
//
// public Sender(final long senderId, final String fromMail, final String replytoMail, final String name)
// {
// dataNode = ConnectionFactory.getSenderIndex().get(IndexTypes.SENDER_ID, senderId).getSingle();
// if (dataNode != null)
// {
// throw new RuntimeException("This sender does already exist");
// }
//
// Transaction tx = ConnectionFactory.getDatabase().beginTx();
// try
// {
// dataNode = ConnectionFactory.getDatabase().createNode();
// writeProperty(ID, senderId);
// writeProperty("type", getClass().getName());
// writeProperty(NAME, name);
// writeProperty(FROM_MAIL, fromMail);
// writeProperty(REPLYTO_MAIL, replytoMail);
//
// ConnectionFactory.getSenderIndex().add(this.dataNode, IndexTypes.SENDER_ID, senderId);
// ConnectionFactory.getSenderIndex().add(this.dataNode, IndexTypes.TYPE, getClass().getName());
// ConnectionFactory.getDatabase().getReferenceNode().createRelationshipTo(dataNode, RelationTypes.SENDER_REFERENCE);
// tx.success();
// }
// catch (Exception e)
// {
// tx.failure();
// }
// finally
// {
// tx.finish();
// }
// }
//
// public Node getDataNode()
// {
// return dataNode;
// }
//
// public long getId()
// {
// return getProperty(Long.class, ID, false);
// }
//
// public String getName()
// {
// return getProperty(String.class, NAME);
// }
//
// public String getFromMail()
// {
// return getProperty(String.class, FROM_MAIL);
// }
//
// public String getReplytoMail()
// {
// return getProperty(String.class, REPLYTO_MAIL);
// }
//
// public void setName(String name)
// {
// writeProperty(NAME, name);
// }
//
// public void setFromMail(String fromMail)
// {
// writeProperty(FROM_MAIL, fromMail);
// }
//
// public void setReplytoMail(String replytoMail)
// {
// writeProperty(REPLYTO_MAIL, replytoMail);
// }
//
// public Relationship addSentMail(Mail mail)
// {
// Transaction tx = ConnectionFactory.getDatabase().beginTx();
// Relationship relation = null;
// try
// {
// Node recipientNode = mail.getDataNode();
// relation = dataNode.createRelationshipTo(recipientNode, RelationTypes.SENT_EMAIL);
// relation.setProperty("date", new Date().getTime());
// tx.success();
// }
// catch (Exception e)
// {
// tx.failure();
// }
// finally
// {
// tx.finish();
// }
// return relation;
// }
//
// public Iterable<Relationship> getSentMails()
// {
// return dataNode.getRelationships(RelationTypes.SENT_EMAIL);
// }
//
// public int getSentMailsCount()
// {
// int count = 0;
// final Iterable<Relationship> sentMails = getSentMails();
// for (Relationship rel : sentMails)
// {
// ++count;
// }
// return count;
// }
//
//
// public static IndexHits<Node> getAll()
// {
// return ConnectionFactory.getSenderIndex().get("type", Sender.class.getName());
// }
// }
| import com.trivago.mail.pigeon.bean.Sender;
import com.vaadin.data.util.BeanContainer;
import com.vaadin.terminal.ThemeResource;
import com.vaadin.ui.*;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.index.IndexHits;
import java.util.ArrayList;
import java.util.List; | /**
* Copyright (C) 2011-2012 trivago GmbH <[email protected]>, <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.trivago.mail.pigeon.web.components.sender;
public class SenderList extends CustomComponent
{
private Table viewTable;
| // Path: pigeon-common/src/main/java/com/trivago/mail/pigeon/bean/Sender.java
// public class Sender extends AbstractBean
// {
// public static final String ID = "sender_id";
//
// public static final String NAME = "name";
//
// public static final String FROM_MAIL = "from_mail";
//
// public static final String REPLYTO_MAIL = "reply_to_mail";
//
// public Sender(final Node underlayingNode)
// {
// this.dataNode = underlayingNode;
// }
//
// public Sender(final long senderId)
// {
// dataNode = ConnectionFactory.getSenderIndex().get(IndexTypes.SENDER_ID, senderId).getSingle();
// }
//
// public Sender(final long senderId, final String fromMail, final String replytoMail, final String name)
// {
// dataNode = ConnectionFactory.getSenderIndex().get(IndexTypes.SENDER_ID, senderId).getSingle();
// if (dataNode != null)
// {
// throw new RuntimeException("This sender does already exist");
// }
//
// Transaction tx = ConnectionFactory.getDatabase().beginTx();
// try
// {
// dataNode = ConnectionFactory.getDatabase().createNode();
// writeProperty(ID, senderId);
// writeProperty("type", getClass().getName());
// writeProperty(NAME, name);
// writeProperty(FROM_MAIL, fromMail);
// writeProperty(REPLYTO_MAIL, replytoMail);
//
// ConnectionFactory.getSenderIndex().add(this.dataNode, IndexTypes.SENDER_ID, senderId);
// ConnectionFactory.getSenderIndex().add(this.dataNode, IndexTypes.TYPE, getClass().getName());
// ConnectionFactory.getDatabase().getReferenceNode().createRelationshipTo(dataNode, RelationTypes.SENDER_REFERENCE);
// tx.success();
// }
// catch (Exception e)
// {
// tx.failure();
// }
// finally
// {
// tx.finish();
// }
// }
//
// public Node getDataNode()
// {
// return dataNode;
// }
//
// public long getId()
// {
// return getProperty(Long.class, ID, false);
// }
//
// public String getName()
// {
// return getProperty(String.class, NAME);
// }
//
// public String getFromMail()
// {
// return getProperty(String.class, FROM_MAIL);
// }
//
// public String getReplytoMail()
// {
// return getProperty(String.class, REPLYTO_MAIL);
// }
//
// public void setName(String name)
// {
// writeProperty(NAME, name);
// }
//
// public void setFromMail(String fromMail)
// {
// writeProperty(FROM_MAIL, fromMail);
// }
//
// public void setReplytoMail(String replytoMail)
// {
// writeProperty(REPLYTO_MAIL, replytoMail);
// }
//
// public Relationship addSentMail(Mail mail)
// {
// Transaction tx = ConnectionFactory.getDatabase().beginTx();
// Relationship relation = null;
// try
// {
// Node recipientNode = mail.getDataNode();
// relation = dataNode.createRelationshipTo(recipientNode, RelationTypes.SENT_EMAIL);
// relation.setProperty("date", new Date().getTime());
// tx.success();
// }
// catch (Exception e)
// {
// tx.failure();
// }
// finally
// {
// tx.finish();
// }
// return relation;
// }
//
// public Iterable<Relationship> getSentMails()
// {
// return dataNode.getRelationships(RelationTypes.SENT_EMAIL);
// }
//
// public int getSentMailsCount()
// {
// int count = 0;
// final Iterable<Relationship> sentMails = getSentMails();
// for (Relationship rel : sentMails)
// {
// ++count;
// }
// return count;
// }
//
//
// public static IndexHits<Node> getAll()
// {
// return ConnectionFactory.getSenderIndex().get("type", Sender.class.getName());
// }
// }
// Path: pigeon-web/src/main/java/com/trivago/mail/pigeon/web/components/sender/SenderList.java
import com.trivago.mail.pigeon.bean.Sender;
import com.vaadin.data.util.BeanContainer;
import com.vaadin.terminal.ThemeResource;
import com.vaadin.ui.*;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.index.IndexHits;
import java.util.ArrayList;
import java.util.List;
/**
* Copyright (C) 2011-2012 trivago GmbH <[email protected]>, <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.trivago.mail.pigeon.web.components.sender;
public class SenderList extends CustomComponent
{
private Table viewTable;
| private BeanContainer<Long, Sender> beanContainer; |
trivago/Mail-Pigeon | pigeon-common/src/main/java/com/trivago/mail/pigeon/storage/ConnectionFactory.java | // Path: pigeon-common/src/main/java/com/trivago/mail/pigeon/configuration/Settings.java
// public class Settings
// {
// private static final org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(Settings.class);
//
// private static Settings instance;
//
// private Configuration configuration;
//
// public static Settings create()
// {
// return create(false);
// }
//
// public static Settings create(boolean nocache)
// {
// return create(null, nocache);
// }
//
// public static Settings create(String fileName, boolean nocache)
// {
// log.trace("Settings instance requested");
// if (fileName == null && instance != null && !nocache)
// {
// log.trace("Returning cached instance");
// return instance;
// }
// else if (fileName == null && instance == null)
// {
// log.trace("Requesting ENV PIDGEON_CONFIG as path to properties as fileName was null");
//
// String propertyFileName = System.getenv("PIDGEON_CONFIG");
//
// if (propertyFileName == null || propertyFileName.equals(""))
// {
// log.warn("ENV is empty and no filename was given -> no config properties found! Using configuration.properties");
// }
//
// URL resource = Thread.currentThread().getContextClassLoader().getResource("configuration.properties");
// propertyFileName = resource.toExternalForm();
// instance = new Settings();
//
// try
// {
// instance.setConfiguration(new PropertiesConfiguration(propertyFileName));
// }
// catch (ConfigurationException e)
// {
// log.error(e);
// throw new ConfigurationRuntimeException(e);
// }
// }
// else if (fileName != null && instance == null)
// {
// log.trace("Requesting file properties from " + fileName);
// instance = new Settings();
//
// try
// {
// instance.setConfiguration(new PropertiesConfiguration(fileName));
// }
// catch (ConfigurationException e)
// {
// log.error(e);
// throw new ConfigurationRuntimeException(e);
// }
// }
// return instance;
// }
//
// public Configuration getConfiguration()
// {
// return configuration;
// }
//
// public void setConfiguration(Configuration configuration)
// {
// this.configuration = configuration;
// }
// }
| import com.trivago.mail.pigeon.configuration.Settings;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.index.Index;
import org.neo4j.kernel.AbstractGraphDatabase;
import org.neo4j.kernel.EmbeddedGraphDatabase;
import org.neo4j.server.WrappingNeoServerBootstrapper;
| /**
* Copyright (C) 2011-2012 trivago GmbH <[email protected]>, <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.trivago.mail.pigeon.storage;
public class ConnectionFactory
{
| // Path: pigeon-common/src/main/java/com/trivago/mail/pigeon/configuration/Settings.java
// public class Settings
// {
// private static final org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(Settings.class);
//
// private static Settings instance;
//
// private Configuration configuration;
//
// public static Settings create()
// {
// return create(false);
// }
//
// public static Settings create(boolean nocache)
// {
// return create(null, nocache);
// }
//
// public static Settings create(String fileName, boolean nocache)
// {
// log.trace("Settings instance requested");
// if (fileName == null && instance != null && !nocache)
// {
// log.trace("Returning cached instance");
// return instance;
// }
// else if (fileName == null && instance == null)
// {
// log.trace("Requesting ENV PIDGEON_CONFIG as path to properties as fileName was null");
//
// String propertyFileName = System.getenv("PIDGEON_CONFIG");
//
// if (propertyFileName == null || propertyFileName.equals(""))
// {
// log.warn("ENV is empty and no filename was given -> no config properties found! Using configuration.properties");
// }
//
// URL resource = Thread.currentThread().getContextClassLoader().getResource("configuration.properties");
// propertyFileName = resource.toExternalForm();
// instance = new Settings();
//
// try
// {
// instance.setConfiguration(new PropertiesConfiguration(propertyFileName));
// }
// catch (ConfigurationException e)
// {
// log.error(e);
// throw new ConfigurationRuntimeException(e);
// }
// }
// else if (fileName != null && instance == null)
// {
// log.trace("Requesting file properties from " + fileName);
// instance = new Settings();
//
// try
// {
// instance.setConfiguration(new PropertiesConfiguration(fileName));
// }
// catch (ConfigurationException e)
// {
// log.error(e);
// throw new ConfigurationRuntimeException(e);
// }
// }
// return instance;
// }
//
// public Configuration getConfiguration()
// {
// return configuration;
// }
//
// public void setConfiguration(Configuration configuration)
// {
// this.configuration = configuration;
// }
// }
// Path: pigeon-common/src/main/java/com/trivago/mail/pigeon/storage/ConnectionFactory.java
import com.trivago.mail.pigeon.configuration.Settings;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.index.Index;
import org.neo4j.kernel.AbstractGraphDatabase;
import org.neo4j.kernel.EmbeddedGraphDatabase;
import org.neo4j.server.WrappingNeoServerBootstrapper;
/**
* Copyright (C) 2011-2012 trivago GmbH <[email protected]>, <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.trivago.mail.pigeon.storage;
public class ConnectionFactory
{
| private static AbstractGraphDatabase graphDb = new EmbeddedGraphDatabase(Settings.create().getConfiguration().getString("neo4j.path"));
|
trivago/Mail-Pigeon | pigeon-web/src/main/java/com/trivago/mail/pigeon/web/components/groups/GroupSelectBox.java | // Path: pigeon-common/src/main/java/com/trivago/mail/pigeon/bean/RecipientGroup.java
// public class RecipientGroup extends AbstractBean
// {
// public static final String ID = "group_id";
//
// public static final String NAME = "name";
//
// public static final String DATE = "date";
//
// public RecipientGroup(final Node underlayingNode)
// {
// this.dataNode = underlayingNode;
// }
//
// public RecipientGroup(final long groupId)
// {
// dataNode = ConnectionFactory.getGroupIndex().get(IndexTypes.GROUP_ID, groupId).getSingle();
// if (dataNode == null)
// {
// Transaction tx = ConnectionFactory.getDatabase().beginTx();
// try
// {
// dataNode = ConnectionFactory.getDatabase().createNode();
// writeProperty(ID, groupId);
// writeProperty("type", getClass().getName());
// writeProperty(NAME, "DefaultGroup");
// ConnectionFactory.getGroupIndex().add(this.dataNode, IndexTypes.GROUP_ID, groupId);
// ConnectionFactory.getGroupIndex().add(this.dataNode, IndexTypes.TYPE, getClass().getName());
// ConnectionFactory.getDatabase().getReferenceNode().createRelationshipTo(dataNode, RelationTypes.GROUP_REFERENCE);
//
// tx.success();
// }
// catch (Exception e)
// {
// log.error(e);
// tx.failure();
// }
// finally
// {
// tx.finish();
// }
// }
// }
//
// public RecipientGroup(final long groupId, final String name)
// {
// Transaction tx = ConnectionFactory.getDatabase().beginTx();
// try
// {
// dataNode = ConnectionFactory.getDatabase().createNode();
// writeProperty(ID, groupId);
// writeProperty("type", getClass().getName());
// writeProperty(NAME, name);
// ConnectionFactory.getGroupIndex().add(this.dataNode, IndexTypes.GROUP_ID, groupId);
// ConnectionFactory.getGroupIndex().add(this.dataNode, IndexTypes.TYPE, getClass().getName());
// ConnectionFactory.getDatabase().getReferenceNode().createRelationshipTo(dataNode, RelationTypes.GROUP_REFERENCE);
//
// tx.success();
// }
// catch (Exception e)
// {
// log.error(e);
// tx.failure();
// }
// finally
// {
// tx.finish();
// }
//
// }
//
// public Node getDataNode()
// {
// return dataNode;
// }
//
// public long getId()
// {
// return getProperty(Long.class, ID, false);
// }
//
// public String getName()
// {
// return getProperty(String.class, NAME);
// }
//
// public Relationship addRecipient(Recipient recipient)
// {
// Transaction tx = ConnectionFactory.getDatabase().beginTx();
// Relationship relation = null;
// try
// {
// Node recipientNode = recipient.getDataNode();
// relation = dataNode.createRelationshipTo(recipientNode, RelationTypes.BELONGS_TO_GROUP);
// relation.setProperty(DATE, new Date().getTime());
// tx.success();
//
// }
// catch (Exception e)
// {
// log.error(e);
// tx.failure();
// }
// finally
// {
// tx.finish();
// }
// return relation;
// }
//
// public Iterable<Relationship> getRecipients()
// {
// return dataNode.getRelationships(RelationTypes.BELONGS_TO_GROUP);
// }
//
// public static IndexHits<Node> getAll()
// {
// return ConnectionFactory.getGroupIndex().get("type", RecipientGroup.class.getName());
// }
//
// public void setName(String name)
// {
// writeProperty(NAME, name);
// }
// }
| import com.trivago.mail.pigeon.bean.RecipientGroup;
import com.vaadin.data.Property;
import com.vaadin.ui.AbstractSelect;
import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.Panel;
import com.vaadin.ui.Select;
import org.apache.log4j.Logger;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.index.IndexHits; | {
Panel rootPanel = new Panel("Select Recipient Group");
select = new Select("Available Groups");
select.setFilteringMode(AbstractSelect.Filtering.FILTERINGMODE_CONTAINS);
select.setNullSelectionAllowed(false);
reloadSelect();
select.addListener(new Select.ValueChangeListener()
{
@Override
public void valueChange(Property.ValueChangeEvent event)
{
selectedGroup = (Long) event.getProperty().getValue();
log.debug("Group Select Value: " + selectedGroup);
}
});
rootPanel.addComponent(select);
setCompositionRoot(rootPanel);
log.debug("Init groups done.");
}
public static void reloadSelect()
{
log.debug("Refresh select triggered");
if (select.getItemIds().size() > 0)
{
log.debug("Clearing select");
select.removeAllItems();
}
| // Path: pigeon-common/src/main/java/com/trivago/mail/pigeon/bean/RecipientGroup.java
// public class RecipientGroup extends AbstractBean
// {
// public static final String ID = "group_id";
//
// public static final String NAME = "name";
//
// public static final String DATE = "date";
//
// public RecipientGroup(final Node underlayingNode)
// {
// this.dataNode = underlayingNode;
// }
//
// public RecipientGroup(final long groupId)
// {
// dataNode = ConnectionFactory.getGroupIndex().get(IndexTypes.GROUP_ID, groupId).getSingle();
// if (dataNode == null)
// {
// Transaction tx = ConnectionFactory.getDatabase().beginTx();
// try
// {
// dataNode = ConnectionFactory.getDatabase().createNode();
// writeProperty(ID, groupId);
// writeProperty("type", getClass().getName());
// writeProperty(NAME, "DefaultGroup");
// ConnectionFactory.getGroupIndex().add(this.dataNode, IndexTypes.GROUP_ID, groupId);
// ConnectionFactory.getGroupIndex().add(this.dataNode, IndexTypes.TYPE, getClass().getName());
// ConnectionFactory.getDatabase().getReferenceNode().createRelationshipTo(dataNode, RelationTypes.GROUP_REFERENCE);
//
// tx.success();
// }
// catch (Exception e)
// {
// log.error(e);
// tx.failure();
// }
// finally
// {
// tx.finish();
// }
// }
// }
//
// public RecipientGroup(final long groupId, final String name)
// {
// Transaction tx = ConnectionFactory.getDatabase().beginTx();
// try
// {
// dataNode = ConnectionFactory.getDatabase().createNode();
// writeProperty(ID, groupId);
// writeProperty("type", getClass().getName());
// writeProperty(NAME, name);
// ConnectionFactory.getGroupIndex().add(this.dataNode, IndexTypes.GROUP_ID, groupId);
// ConnectionFactory.getGroupIndex().add(this.dataNode, IndexTypes.TYPE, getClass().getName());
// ConnectionFactory.getDatabase().getReferenceNode().createRelationshipTo(dataNode, RelationTypes.GROUP_REFERENCE);
//
// tx.success();
// }
// catch (Exception e)
// {
// log.error(e);
// tx.failure();
// }
// finally
// {
// tx.finish();
// }
//
// }
//
// public Node getDataNode()
// {
// return dataNode;
// }
//
// public long getId()
// {
// return getProperty(Long.class, ID, false);
// }
//
// public String getName()
// {
// return getProperty(String.class, NAME);
// }
//
// public Relationship addRecipient(Recipient recipient)
// {
// Transaction tx = ConnectionFactory.getDatabase().beginTx();
// Relationship relation = null;
// try
// {
// Node recipientNode = recipient.getDataNode();
// relation = dataNode.createRelationshipTo(recipientNode, RelationTypes.BELONGS_TO_GROUP);
// relation.setProperty(DATE, new Date().getTime());
// tx.success();
//
// }
// catch (Exception e)
// {
// log.error(e);
// tx.failure();
// }
// finally
// {
// tx.finish();
// }
// return relation;
// }
//
// public Iterable<Relationship> getRecipients()
// {
// return dataNode.getRelationships(RelationTypes.BELONGS_TO_GROUP);
// }
//
// public static IndexHits<Node> getAll()
// {
// return ConnectionFactory.getGroupIndex().get("type", RecipientGroup.class.getName());
// }
//
// public void setName(String name)
// {
// writeProperty(NAME, name);
// }
// }
// Path: pigeon-web/src/main/java/com/trivago/mail/pigeon/web/components/groups/GroupSelectBox.java
import com.trivago.mail.pigeon.bean.RecipientGroup;
import com.vaadin.data.Property;
import com.vaadin.ui.AbstractSelect;
import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.Panel;
import com.vaadin.ui.Select;
import org.apache.log4j.Logger;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.index.IndexHits;
{
Panel rootPanel = new Panel("Select Recipient Group");
select = new Select("Available Groups");
select.setFilteringMode(AbstractSelect.Filtering.FILTERINGMODE_CONTAINS);
select.setNullSelectionAllowed(false);
reloadSelect();
select.addListener(new Select.ValueChangeListener()
{
@Override
public void valueChange(Property.ValueChangeEvent event)
{
selectedGroup = (Long) event.getProperty().getValue();
log.debug("Group Select Value: " + selectedGroup);
}
});
rootPanel.addComponent(select);
setCompositionRoot(rootPanel);
log.debug("Init groups done.");
}
public static void reloadSelect()
{
log.debug("Refresh select triggered");
if (select.getItemIds().size() > 0)
{
log.debug("Clearing select");
select.removeAllItems();
}
| final IndexHits<Node> indexHits = RecipientGroup.getAll(); |
trivago/Mail-Pigeon | pigeon-common/src/main/java/com/trivago/mail/pigeon/queue/ConnectionPool.java | // Path: pigeon-common/src/main/java/com/trivago/mail/pigeon/configuration/Settings.java
// public class Settings
// {
// private static final org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(Settings.class);
//
// private static Settings instance;
//
// private Configuration configuration;
//
// public static Settings create()
// {
// return create(false);
// }
//
// public static Settings create(boolean nocache)
// {
// return create(null, nocache);
// }
//
// public static Settings create(String fileName, boolean nocache)
// {
// log.trace("Settings instance requested");
// if (fileName == null && instance != null && !nocache)
// {
// log.trace("Returning cached instance");
// return instance;
// }
// else if (fileName == null && instance == null)
// {
// log.trace("Requesting ENV PIDGEON_CONFIG as path to properties as fileName was null");
//
// String propertyFileName = System.getenv("PIDGEON_CONFIG");
//
// if (propertyFileName == null || propertyFileName.equals(""))
// {
// log.warn("ENV is empty and no filename was given -> no config properties found! Using configuration.properties");
// }
//
// URL resource = Thread.currentThread().getContextClassLoader().getResource("configuration.properties");
// propertyFileName = resource.toExternalForm();
// instance = new Settings();
//
// try
// {
// instance.setConfiguration(new PropertiesConfiguration(propertyFileName));
// }
// catch (ConfigurationException e)
// {
// log.error(e);
// throw new ConfigurationRuntimeException(e);
// }
// }
// else if (fileName != null && instance == null)
// {
// log.trace("Requesting file properties from " + fileName);
// instance = new Settings();
//
// try
// {
// instance.setConfiguration(new PropertiesConfiguration(fileName));
// }
// catch (ConfigurationException e)
// {
// log.error(e);
// throw new ConfigurationRuntimeException(e);
// }
// }
// return instance;
// }
//
// public Configuration getConfiguration()
// {
// return configuration;
// }
//
// public void setConfiguration(Configuration configuration)
// {
// this.configuration = configuration;
// }
// }
| import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import com.trivago.mail.pigeon.configuration.Settings;
import org.apache.commons.configuration.Configuration;
import org.apache.log4j.Logger;
import java.io.IOException; | /**
* Copyright (C) 2011-2012 trivago GmbH <[email protected]>, <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.trivago.mail.pigeon.queue;
/**
* Represents the connection pool for the
*/
public class ConnectionPool
{
private static final Logger log = Logger.getLogger(ConnectionPool.class);
private static Connection connection;
| // Path: pigeon-common/src/main/java/com/trivago/mail/pigeon/configuration/Settings.java
// public class Settings
// {
// private static final org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(Settings.class);
//
// private static Settings instance;
//
// private Configuration configuration;
//
// public static Settings create()
// {
// return create(false);
// }
//
// public static Settings create(boolean nocache)
// {
// return create(null, nocache);
// }
//
// public static Settings create(String fileName, boolean nocache)
// {
// log.trace("Settings instance requested");
// if (fileName == null && instance != null && !nocache)
// {
// log.trace("Returning cached instance");
// return instance;
// }
// else if (fileName == null && instance == null)
// {
// log.trace("Requesting ENV PIDGEON_CONFIG as path to properties as fileName was null");
//
// String propertyFileName = System.getenv("PIDGEON_CONFIG");
//
// if (propertyFileName == null || propertyFileName.equals(""))
// {
// log.warn("ENV is empty and no filename was given -> no config properties found! Using configuration.properties");
// }
//
// URL resource = Thread.currentThread().getContextClassLoader().getResource("configuration.properties");
// propertyFileName = resource.toExternalForm();
// instance = new Settings();
//
// try
// {
// instance.setConfiguration(new PropertiesConfiguration(propertyFileName));
// }
// catch (ConfigurationException e)
// {
// log.error(e);
// throw new ConfigurationRuntimeException(e);
// }
// }
// else if (fileName != null && instance == null)
// {
// log.trace("Requesting file properties from " + fileName);
// instance = new Settings();
//
// try
// {
// instance.setConfiguration(new PropertiesConfiguration(fileName));
// }
// catch (ConfigurationException e)
// {
// log.error(e);
// throw new ConfigurationRuntimeException(e);
// }
// }
// return instance;
// }
//
// public Configuration getConfiguration()
// {
// return configuration;
// }
//
// public void setConfiguration(Configuration configuration)
// {
// this.configuration = configuration;
// }
// }
// Path: pigeon-common/src/main/java/com/trivago/mail/pigeon/queue/ConnectionPool.java
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import com.trivago.mail.pigeon.configuration.Settings;
import org.apache.commons.configuration.Configuration;
import org.apache.log4j.Logger;
import java.io.IOException;
/**
* Copyright (C) 2011-2012 trivago GmbH <[email protected]>, <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.trivago.mail.pigeon.queue;
/**
* Represents the connection pool for the
*/
public class ConnectionPool
{
private static final Logger log = Logger.getLogger(ConnectionPool.class);
private static Connection connection;
| private static Settings settings = Settings.create(); |
trivago/Mail-Pigeon | pigeon-common/src/main/java/com/trivago/mail/pigeon/bean/AbstractBean.java | // Path: pigeon-common/src/main/java/com/trivago/mail/pigeon/storage/ConnectionFactory.java
// public class ConnectionFactory
// {
//
// private static AbstractGraphDatabase graphDb = new EmbeddedGraphDatabase(Settings.create().getConfiguration().getString("neo4j.path"));
//
// private static Index<Node> newsletterIndex;
//
// private static Index<Node> userIndex;
//
// private static Index<Node> groupIndex;
//
// private static Index<Node> senderIndex;
//
// private static Index<Node> bounceIndex;
//
// private static Index<Node> campaignIndex;
//
// private static Index<Node> templateIndex;
//
// private static Index<Node> tagIndex;
//
// public static final long DEFAULT_BOUNCE_NODE = 1337L;
//
// private static boolean notStarted = true;
//
// /**
// * The wrapper for the graph db to be exposed as server
// */
// private static WrappingNeoServerBootstrapper srv;
//
// static
// {
// newsletterIndex = graphDb.index().forNodes("newsletter");
// userIndex = graphDb.index().forNodes("user");
// groupIndex = graphDb.index().forNodes("group");
// senderIndex = graphDb.index().forNodes("sender");
// senderIndex = graphDb.index().forNodes("bounce");
// campaignIndex = graphDb.index().forNodes("campaign");
// templateIndex = graphDb.index().forNodes("template");
//
// if (notStarted)
// {
// srv = new WrappingNeoServerBootstrapper(graphDb);
// srv.start();
// registerShutdownHook();
// notStarted = false;
// }
// }
//
// private ConnectionFactory()
// {
// }
//
// /**
// * Singleton like getter for the graph db.
// *
// * @return the graphdb instance
// */
// public static GraphDatabaseService getDatabase()
// {
// return graphDb;
// }
//
// public static Index<Node> getNewsletterIndex()
// {
// return newsletterIndex;
// }
//
// public static Index<Node> getUserIndex()
// {
// return userIndex;
// }
//
// public static Index<Node> getGroupIndex()
// {
// return groupIndex;
// }
//
// public static Index<Node> getSenderIndex()
// {
// return senderIndex;
// }
//
// public static Index<Node> getBounceIndex()
// {
// return bounceIndex;
// }
//
// public static Index<Node> getCampaignIndex()
// {
// return campaignIndex;
// }
//
// public static Index<Node> getTemplateIndex()
// {
// return templateIndex;
// }
//
// public static Index<Node> getTagIndex()
// {
// return tagIndex;
// }
//
// private static void shutdown()
// {
// srv.stop();
// graphDb.shutdown();
// }
//
// private static void registerShutdownHook()
// {
// // Registers a shutdown hook for the Neo4j and index service instances
// // so that it shuts down nicely when the VM exits (even if you
// // "Ctrl-C" the running example before it's completed)
// Runtime.getRuntime().addShutdownHook(new Thread()
// {
// @Override
// public void run()
// {
// shutdown();
// }
// });
// }
// }
| import com.trivago.mail.pigeon.storage.ConnectionFactory;
import org.apache.log4j.Logger;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.NotFoundException;
import org.neo4j.graphdb.Transaction;
import org.svenson.JSONProperty;
| /**
* Copyright (C) 2011-2012 trivago GmbH <[email protected]>, <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.trivago.mail.pigeon.bean;
/**
* Abstract Bean as parent for the other entity beans. Your new beans should
* inherit from this one.
*
* @author Mario Mueller [email protected]
*/
public abstract class AbstractBean
{
/**
* The data node from neo4j
*/
protected Node dataNode;
protected static final Logger log = Logger.getLogger("com.trivago.mail.pigeon.bean");
/**
* The Node class is a wrapper from the neo4j libraries.
*
* @return returns the data node from neo4j
*/
@JSONProperty(ignore = true)
public Node getDataNode()
{
return dataNode;
}
/**
* Wrapper for writing properties directly to the node. Do not use this within another transaction as it will fail.
*
* @param key name of the property
* @param value value of the property. Should be of type String, a boxed scalar or at least serializable.
*/
protected void writeProperty(final String key, final Object value)
{
| // Path: pigeon-common/src/main/java/com/trivago/mail/pigeon/storage/ConnectionFactory.java
// public class ConnectionFactory
// {
//
// private static AbstractGraphDatabase graphDb = new EmbeddedGraphDatabase(Settings.create().getConfiguration().getString("neo4j.path"));
//
// private static Index<Node> newsletterIndex;
//
// private static Index<Node> userIndex;
//
// private static Index<Node> groupIndex;
//
// private static Index<Node> senderIndex;
//
// private static Index<Node> bounceIndex;
//
// private static Index<Node> campaignIndex;
//
// private static Index<Node> templateIndex;
//
// private static Index<Node> tagIndex;
//
// public static final long DEFAULT_BOUNCE_NODE = 1337L;
//
// private static boolean notStarted = true;
//
// /**
// * The wrapper for the graph db to be exposed as server
// */
// private static WrappingNeoServerBootstrapper srv;
//
// static
// {
// newsletterIndex = graphDb.index().forNodes("newsletter");
// userIndex = graphDb.index().forNodes("user");
// groupIndex = graphDb.index().forNodes("group");
// senderIndex = graphDb.index().forNodes("sender");
// senderIndex = graphDb.index().forNodes("bounce");
// campaignIndex = graphDb.index().forNodes("campaign");
// templateIndex = graphDb.index().forNodes("template");
//
// if (notStarted)
// {
// srv = new WrappingNeoServerBootstrapper(graphDb);
// srv.start();
// registerShutdownHook();
// notStarted = false;
// }
// }
//
// private ConnectionFactory()
// {
// }
//
// /**
// * Singleton like getter for the graph db.
// *
// * @return the graphdb instance
// */
// public static GraphDatabaseService getDatabase()
// {
// return graphDb;
// }
//
// public static Index<Node> getNewsletterIndex()
// {
// return newsletterIndex;
// }
//
// public static Index<Node> getUserIndex()
// {
// return userIndex;
// }
//
// public static Index<Node> getGroupIndex()
// {
// return groupIndex;
// }
//
// public static Index<Node> getSenderIndex()
// {
// return senderIndex;
// }
//
// public static Index<Node> getBounceIndex()
// {
// return bounceIndex;
// }
//
// public static Index<Node> getCampaignIndex()
// {
// return campaignIndex;
// }
//
// public static Index<Node> getTemplateIndex()
// {
// return templateIndex;
// }
//
// public static Index<Node> getTagIndex()
// {
// return tagIndex;
// }
//
// private static void shutdown()
// {
// srv.stop();
// graphDb.shutdown();
// }
//
// private static void registerShutdownHook()
// {
// // Registers a shutdown hook for the Neo4j and index service instances
// // so that it shuts down nicely when the VM exits (even if you
// // "Ctrl-C" the running example before it's completed)
// Runtime.getRuntime().addShutdownHook(new Thread()
// {
// @Override
// public void run()
// {
// shutdown();
// }
// });
// }
// }
// Path: pigeon-common/src/main/java/com/trivago/mail/pigeon/bean/AbstractBean.java
import com.trivago.mail.pigeon.storage.ConnectionFactory;
import org.apache.log4j.Logger;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.NotFoundException;
import org.neo4j.graphdb.Transaction;
import org.svenson.JSONProperty;
/**
* Copyright (C) 2011-2012 trivago GmbH <[email protected]>, <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.trivago.mail.pigeon.bean;
/**
* Abstract Bean as parent for the other entity beans. Your new beans should
* inherit from this one.
*
* @author Mario Mueller [email protected]
*/
public abstract class AbstractBean
{
/**
* The data node from neo4j
*/
protected Node dataNode;
protected static final Logger log = Logger.getLogger("com.trivago.mail.pigeon.bean");
/**
* The Node class is a wrapper from the neo4j libraries.
*
* @return returns the data node from neo4j
*/
@JSONProperty(ignore = true)
public Node getDataNode()
{
return dataNode;
}
/**
* Wrapper for writing properties directly to the node. Do not use this within another transaction as it will fail.
*
* @param key name of the property
* @param value value of the property. Should be of type String, a boxed scalar or at least serializable.
*/
protected void writeProperty(final String key, final Object value)
{
| Transaction tx = ConnectionFactory.getDatabase().beginTx();
|
trivago/Mail-Pigeon | pigeon-web/src/main/java/com/trivago/mail/pigeon/web/components/templates/ModalAddTemplate.java | // Path: pigeon-common/src/main/java/com/trivago/mail/pigeon/bean/MailTemplate.java
// public class MailTemplate extends AbstractBean
// {
// public static final String ID = "template_id";
// public static final String SUBJECT = "subject";
// public static final String TEXT = "text_content";
// public static final String HTML = "html_content";
// public static final String TITLE = "title";
//
//
// public MailTemplate(final Node underlayingNode)
// {
// this.dataNode = underlayingNode;
// }
//
// public MailTemplate(final long templateId)
// {
// dataNode = ConnectionFactory.getTemplateIndex().get(IndexTypes.TEMPLATE_ID, templateId).getSingle();
// }
//
// public MailTemplate(final long templateId, final String title, final String text, final String html, final String subject)
// {
// Transaction tx = ConnectionFactory.getDatabase().beginTx();
// try
// {
// dataNode = ConnectionFactory.getDatabase().createNode();
// writeProperty(ID, templateId);
// writeProperty("type", getClass().getName());
// writeProperty(SUBJECT, subject);
// writeProperty(TEXT, text);
// writeProperty(HTML, html);
// writeProperty(TITLE, title);
// ConnectionFactory.getTemplateIndex().add(this.dataNode, IndexTypes.TEMPLATE_ID, templateId);
// ConnectionFactory.getTemplateIndex().add(this.dataNode, IndexTypes.TYPE, getClass().getName());
// ConnectionFactory.getDatabase().getReferenceNode().createRelationshipTo(dataNode, RelationTypes.MAIL_TEMPLATE_REFERENCE);
// tx.success();
// }
// catch (Exception e)
// {
// tx.failure();
// }
// finally
// {
// tx.finish();
// }
// }
//
// public long getId()
// {
// return getProperty(Long.class, ID, false);
// }
//
// public String getSubject()
// {
// return getProperty(String.class, SUBJECT);
// }
//
// public void setSubject(final String subject)
// {
// writeProperty(SUBJECT, subject);
// }
//
// public Node getDataNode()
// {
// return this.dataNode;
// }
//
// public String getText()
// {
// return getProperty(String.class, TEXT);
// }
//
// public void setText(final String text)
// {
// writeProperty(TEXT, text);
// }
//
// public String getHtml()
// {
// return getProperty(String.class, HTML);
// }
//
// public void setHtml(final String html)
// {
// writeProperty(HTML, html);
// }
//
// public String getTitle()
// {
// return getProperty(String.class, TITLE);
// }
//
// public void setTitle(final String title)
// {
// writeProperty(TITLE, title);
// }
//
// public static IndexHits<Node> getAll()
// {
// return ConnectionFactory.getTemplateIndex().get(IndexTypes.TYPE, MailTemplate.class.getName());
// }
// }
//
// Path: pigeon-common/src/main/java/com/trivago/mail/pigeon/storage/Util.java
// public abstract class Util
// {
// public static <T> List<T> indexHitsToList(Class<T> clazz, IndexHits<Node> hitList)
// {
// List<T> list = new ArrayList<T>();
// for (Node node : hitList)
// {
// T s = null;
// try
// {
// s = clazz.getConstructor(new Class[]{node.getClass()}).newInstance(node);
// list.add(s);
// }
// catch (InstantiationException e)
// {
// e.printStackTrace();
// }
// catch (IllegalAccessException e)
// {
// e.printStackTrace();
// }
// catch (InvocationTargetException e)
// {
// e.printStackTrace();
// }
// catch (NoSuchMethodException e)
// {
// e.printStackTrace();
// }
//
// }
// return list;
// }
//
// public static long generateId()
// {
// return Math.round(new Date().getTime() * Math.random());
// }
// }
| import com.trivago.mail.pigeon.bean.MailTemplate;
import com.trivago.mail.pigeon.storage.Util;
import com.vaadin.data.util.BeanItem;
import com.vaadin.terminal.ExternalResource;
import com.vaadin.terminal.UserError;
import com.vaadin.ui.*;
import org.vaadin.openesignforms.ckeditor.CKEditorTextField;
| }
else
{
subject.setComponentError(null);
}
if (htmlContent.getValue().equals(""))
{
htmlContent.setComponentError(new UserError("Please provide some HTML content"));
hasError = true;
}
else
{
htmlContent.setComponentError(null);
}
if (textContent.getValue().equals(""))
{
textContent.setComponentError(new UserError("Please provide some text content"));
hasError = true;
}
else
{
textContent.setComponentError(null);
}
if (!hasError)
{
if (templateId == null)
{
| // Path: pigeon-common/src/main/java/com/trivago/mail/pigeon/bean/MailTemplate.java
// public class MailTemplate extends AbstractBean
// {
// public static final String ID = "template_id";
// public static final String SUBJECT = "subject";
// public static final String TEXT = "text_content";
// public static final String HTML = "html_content";
// public static final String TITLE = "title";
//
//
// public MailTemplate(final Node underlayingNode)
// {
// this.dataNode = underlayingNode;
// }
//
// public MailTemplate(final long templateId)
// {
// dataNode = ConnectionFactory.getTemplateIndex().get(IndexTypes.TEMPLATE_ID, templateId).getSingle();
// }
//
// public MailTemplate(final long templateId, final String title, final String text, final String html, final String subject)
// {
// Transaction tx = ConnectionFactory.getDatabase().beginTx();
// try
// {
// dataNode = ConnectionFactory.getDatabase().createNode();
// writeProperty(ID, templateId);
// writeProperty("type", getClass().getName());
// writeProperty(SUBJECT, subject);
// writeProperty(TEXT, text);
// writeProperty(HTML, html);
// writeProperty(TITLE, title);
// ConnectionFactory.getTemplateIndex().add(this.dataNode, IndexTypes.TEMPLATE_ID, templateId);
// ConnectionFactory.getTemplateIndex().add(this.dataNode, IndexTypes.TYPE, getClass().getName());
// ConnectionFactory.getDatabase().getReferenceNode().createRelationshipTo(dataNode, RelationTypes.MAIL_TEMPLATE_REFERENCE);
// tx.success();
// }
// catch (Exception e)
// {
// tx.failure();
// }
// finally
// {
// tx.finish();
// }
// }
//
// public long getId()
// {
// return getProperty(Long.class, ID, false);
// }
//
// public String getSubject()
// {
// return getProperty(String.class, SUBJECT);
// }
//
// public void setSubject(final String subject)
// {
// writeProperty(SUBJECT, subject);
// }
//
// public Node getDataNode()
// {
// return this.dataNode;
// }
//
// public String getText()
// {
// return getProperty(String.class, TEXT);
// }
//
// public void setText(final String text)
// {
// writeProperty(TEXT, text);
// }
//
// public String getHtml()
// {
// return getProperty(String.class, HTML);
// }
//
// public void setHtml(final String html)
// {
// writeProperty(HTML, html);
// }
//
// public String getTitle()
// {
// return getProperty(String.class, TITLE);
// }
//
// public void setTitle(final String title)
// {
// writeProperty(TITLE, title);
// }
//
// public static IndexHits<Node> getAll()
// {
// return ConnectionFactory.getTemplateIndex().get(IndexTypes.TYPE, MailTemplate.class.getName());
// }
// }
//
// Path: pigeon-common/src/main/java/com/trivago/mail/pigeon/storage/Util.java
// public abstract class Util
// {
// public static <T> List<T> indexHitsToList(Class<T> clazz, IndexHits<Node> hitList)
// {
// List<T> list = new ArrayList<T>();
// for (Node node : hitList)
// {
// T s = null;
// try
// {
// s = clazz.getConstructor(new Class[]{node.getClass()}).newInstance(node);
// list.add(s);
// }
// catch (InstantiationException e)
// {
// e.printStackTrace();
// }
// catch (IllegalAccessException e)
// {
// e.printStackTrace();
// }
// catch (InvocationTargetException e)
// {
// e.printStackTrace();
// }
// catch (NoSuchMethodException e)
// {
// e.printStackTrace();
// }
//
// }
// return list;
// }
//
// public static long generateId()
// {
// return Math.round(new Date().getTime() * Math.random());
// }
// }
// Path: pigeon-web/src/main/java/com/trivago/mail/pigeon/web/components/templates/ModalAddTemplate.java
import com.trivago.mail.pigeon.bean.MailTemplate;
import com.trivago.mail.pigeon.storage.Util;
import com.vaadin.data.util.BeanItem;
import com.vaadin.terminal.ExternalResource;
import com.vaadin.terminal.UserError;
import com.vaadin.ui.*;
import org.vaadin.openesignforms.ckeditor.CKEditorTextField;
}
else
{
subject.setComponentError(null);
}
if (htmlContent.getValue().equals(""))
{
htmlContent.setComponentError(new UserError("Please provide some HTML content"));
hasError = true;
}
else
{
htmlContent.setComponentError(null);
}
if (textContent.getValue().equals(""))
{
textContent.setComponentError(new UserError("Please provide some text content"));
hasError = true;
}
else
{
textContent.setComponentError(null);
}
if (!hasError)
{
if (templateId == null)
{
| long templateId = Util.generateId();
|
trivago/Mail-Pigeon | pigeon-daemon/src/test/java/com/trivago/TestDateFilter.java | // Path: pigeon-common/src/main/java/com/trivago/mail/pigeon/json/MailTransport.java
// public class MailTransport
// {
// private String from;
//
// private String to;
//
// private String replyTo;
//
// private String subject;
//
// private String html;
//
// private String text;
//
// private String mId;
//
// private String uId;
//
// private Date sendDate;
//
// private boolean enforceSending = false;
//
// private boolean abortSending = false;
//
// public void enforceSending()
// {
// enforceSending = true;
// }
//
// public void abortSending()
// {
// abortSending = true;
// }
//
// public boolean shouldAbortSending()
// {
// return abortSending;
// }
//
// public boolean shouldEnforceSending()
// {
// return enforceSending;
// }
//
// public String getFrom()
// {
// return from;
// }
//
// public void setFrom(String from)
// {
// this.from = from;
// }
//
// public String getTo()
// {
// return to;
// }
//
// public void setTo(String to)
// {
// this.to = to;
// }
//
// public String getReplyTo()
// {
// return replyTo;
// }
//
// public void setReplyTo(String replyTo)
// {
// this.replyTo = replyTo;
// }
//
// public String getSubject()
// {
// return subject;
// }
//
// public void setSubject(String subject)
// {
// this.subject = subject;
// }
//
// public String getHtml()
// {
// return html;
// }
//
// public void setHtml(String html)
// {
// this.html = html;
// }
//
// public String getText()
// {
// return text;
// }
//
// public void setText(String text)
// {
// this.text = text;
// }
//
// public String getmId()
// {
// return mId;
// }
//
// public void setmId(String mId)
// {
// this.mId = mId;
// }
//
// public String getuId()
// {
// return uId;
// }
//
// public void setuId(String uId)
// {
// this.uId = uId;
// }
//
// public Date getSendDate()
// {
// return sendDate;
// }
//
// public void setSendDate(Date sendDate)
// {
// this.sendDate = sendDate;
// }
// }
| import com.trivago.mail.pigeon.daemon.filter.DateFilter;
import com.trivago.mail.pigeon.json.MailTransport;
import org.junit.Test;
import static org.junit.Assert.*;
import java.util.Calendar;
import java.util.Date;
| /**
* Copyright (C) 2011-2012 trivago GmbH <[email protected]>, <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.trivago;
public class TestDateFilter
{
@Test
public void testDateFilterPositive()
{
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
cal.add(Calendar.DAY_OF_MONTH, 5);
Date d = cal.getTime();
| // Path: pigeon-common/src/main/java/com/trivago/mail/pigeon/json/MailTransport.java
// public class MailTransport
// {
// private String from;
//
// private String to;
//
// private String replyTo;
//
// private String subject;
//
// private String html;
//
// private String text;
//
// private String mId;
//
// private String uId;
//
// private Date sendDate;
//
// private boolean enforceSending = false;
//
// private boolean abortSending = false;
//
// public void enforceSending()
// {
// enforceSending = true;
// }
//
// public void abortSending()
// {
// abortSending = true;
// }
//
// public boolean shouldAbortSending()
// {
// return abortSending;
// }
//
// public boolean shouldEnforceSending()
// {
// return enforceSending;
// }
//
// public String getFrom()
// {
// return from;
// }
//
// public void setFrom(String from)
// {
// this.from = from;
// }
//
// public String getTo()
// {
// return to;
// }
//
// public void setTo(String to)
// {
// this.to = to;
// }
//
// public String getReplyTo()
// {
// return replyTo;
// }
//
// public void setReplyTo(String replyTo)
// {
// this.replyTo = replyTo;
// }
//
// public String getSubject()
// {
// return subject;
// }
//
// public void setSubject(String subject)
// {
// this.subject = subject;
// }
//
// public String getHtml()
// {
// return html;
// }
//
// public void setHtml(String html)
// {
// this.html = html;
// }
//
// public String getText()
// {
// return text;
// }
//
// public void setText(String text)
// {
// this.text = text;
// }
//
// public String getmId()
// {
// return mId;
// }
//
// public void setmId(String mId)
// {
// this.mId = mId;
// }
//
// public String getuId()
// {
// return uId;
// }
//
// public void setuId(String uId)
// {
// this.uId = uId;
// }
//
// public Date getSendDate()
// {
// return sendDate;
// }
//
// public void setSendDate(Date sendDate)
// {
// this.sendDate = sendDate;
// }
// }
// Path: pigeon-daemon/src/test/java/com/trivago/TestDateFilter.java
import com.trivago.mail.pigeon.daemon.filter.DateFilter;
import com.trivago.mail.pigeon.json.MailTransport;
import org.junit.Test;
import static org.junit.Assert.*;
import java.util.Calendar;
import java.util.Date;
/**
* Copyright (C) 2011-2012 trivago GmbH <[email protected]>, <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.trivago;
public class TestDateFilter
{
@Test
public void testDateFilterPositive()
{
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
cal.add(Calendar.DAY_OF_MONTH, 5);
Date d = cal.getTime();
| MailTransport mt = new MailTransport();
|
trivago/Mail-Pigeon | pigeon-web/src/main/java/com/trivago/mail/pigeon/web/components/menu/MenuBar.java | // Path: pigeon-web/src/main/java/com/trivago/mail/pigeon/web/MainApp.java
// @SuppressWarnings("serial")
// public class MainApp extends Application
// {
// private Window window;
// private MenuBar menu;
//
// @Override
// public void init()
// {
// //DOMConfigurator.configure(Thread.currentThread().getContextClassLoader().getResource("log4j.xml"));
// // BasicConfigurator.configure();
// window = new Window("Mail Pigeon");
// setMainWindow(window);
//
// int senderSize;
// try
// {
// senderSize = Sender.getAll().size();
// } catch (NoSuchElementException e)
// {
// senderSize = 0;
// }
//
// int recipientGroupSize;
// try
// {
// recipientGroupSize = RecipientGroup.getAll().size();
// } catch (NoSuchElementException e)
// {
// recipientGroupSize = 0;
// }
//
// if (senderSize == 0 && recipientGroupSize == 0)
// {
// startWizard();
// }
// else
// {
// menu = new MenuBar(this);
// window.addComponent(menu);
// setDashBoard();
// }
//
// }
//
// public void initMenu()
// {
// menu = new MenuBar(this);
// window.addComponent(menu);
// }
//
// public void clearWindow()
// {
// window.removeAllComponents();
// initMenu();
// }
//
// public void setDashBoard()
// {
// VerticalLayout dbLayout = new VerticalLayout();
// dbLayout.addComponent(new Label("Can I haz Dashboard?"));
// window.addComponent(dbLayout);
//
// }
//
// public void setNewsletterList()
// {
// NewsletterList newsletterList = new NewsletterList();
// VerticalLayout nlLayout = new VerticalLayout();
// nlLayout.addComponent(newsletterList);
// nlLayout.setMargin(true);
// clearWindow();
// window.addComponent(nlLayout);
// }
//
// public void setSenderList()
// {
// SenderList senderList = new SenderList();
// VerticalLayout slLayout = new VerticalLayout();
// slLayout.addComponent(senderList);
// slLayout.setMargin(true);
// clearWindow();
// window.addComponent(slLayout);
// }
//
// public void setRecipientGroupList()
// {
// GroupList groupList = new GroupList();
// VerticalLayout rgLayout = new VerticalLayout();
// rgLayout.addComponent(groupList);
// rgLayout.setMargin(true);
// clearWindow();
// window.addComponent(rgLayout);
// }
//
// public void setRecipientList()
// {
// RecipientList recipientList = new RecipientList();
// VerticalLayout rLayout = new VerticalLayout();
// rLayout.addComponent(recipientList);
// rLayout.setMargin(true);
// clearWindow();
// window.addComponent(rLayout);
// }
//
// public void setTemplateList()
// {
// TemplateList templateList = new TemplateList();
// VerticalLayout tlLayout = new VerticalLayout();
// tlLayout.addComponent(templateList);
// tlLayout.setMargin(true);
// clearWindow();
// window.addComponent(tlLayout);
// }
//
// public void startWizard()
// {
// SetupWizardComponent wb = new SetupWizardComponent();
// window.addComponent(wb);
// }
//
// public MenuBar getMenu()
// {
// return menu;
// }
//
// public void setMenu(MenuBar menu)
// {
// this.menu = menu;
// }
//
// @Override
// public void close()
// {
// super.close();
// // Registers a shutdown hook for the Neo4j and index service instances
// // so that it shuts down nicely when the VM exits (even if you
// // "Ctrl-C" the running example before it's completed)
// Runtime.getRuntime().addShutdownHook(new Thread()
// {
// @Override
// public void run()
// {
// Logger.getLogger(MainApp.class).info("Shutdown hook called");
// ConnectionFactory.getDatabase().shutdown();
// }
// });
//
// }
// }
| import com.trivago.mail.pigeon.web.MainApp;
import java.lang.reflect.InvocationTargetException;
| /**
* Copyright (C) 2011-2012 trivago GmbH <[email protected]>, <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.trivago.mail.pigeon.web.components.menu;
public class MenuBar extends com.vaadin.ui.MenuBar
{
| // Path: pigeon-web/src/main/java/com/trivago/mail/pigeon/web/MainApp.java
// @SuppressWarnings("serial")
// public class MainApp extends Application
// {
// private Window window;
// private MenuBar menu;
//
// @Override
// public void init()
// {
// //DOMConfigurator.configure(Thread.currentThread().getContextClassLoader().getResource("log4j.xml"));
// // BasicConfigurator.configure();
// window = new Window("Mail Pigeon");
// setMainWindow(window);
//
// int senderSize;
// try
// {
// senderSize = Sender.getAll().size();
// } catch (NoSuchElementException e)
// {
// senderSize = 0;
// }
//
// int recipientGroupSize;
// try
// {
// recipientGroupSize = RecipientGroup.getAll().size();
// } catch (NoSuchElementException e)
// {
// recipientGroupSize = 0;
// }
//
// if (senderSize == 0 && recipientGroupSize == 0)
// {
// startWizard();
// }
// else
// {
// menu = new MenuBar(this);
// window.addComponent(menu);
// setDashBoard();
// }
//
// }
//
// public void initMenu()
// {
// menu = new MenuBar(this);
// window.addComponent(menu);
// }
//
// public void clearWindow()
// {
// window.removeAllComponents();
// initMenu();
// }
//
// public void setDashBoard()
// {
// VerticalLayout dbLayout = new VerticalLayout();
// dbLayout.addComponent(new Label("Can I haz Dashboard?"));
// window.addComponent(dbLayout);
//
// }
//
// public void setNewsletterList()
// {
// NewsletterList newsletterList = new NewsletterList();
// VerticalLayout nlLayout = new VerticalLayout();
// nlLayout.addComponent(newsletterList);
// nlLayout.setMargin(true);
// clearWindow();
// window.addComponent(nlLayout);
// }
//
// public void setSenderList()
// {
// SenderList senderList = new SenderList();
// VerticalLayout slLayout = new VerticalLayout();
// slLayout.addComponent(senderList);
// slLayout.setMargin(true);
// clearWindow();
// window.addComponent(slLayout);
// }
//
// public void setRecipientGroupList()
// {
// GroupList groupList = new GroupList();
// VerticalLayout rgLayout = new VerticalLayout();
// rgLayout.addComponent(groupList);
// rgLayout.setMargin(true);
// clearWindow();
// window.addComponent(rgLayout);
// }
//
// public void setRecipientList()
// {
// RecipientList recipientList = new RecipientList();
// VerticalLayout rLayout = new VerticalLayout();
// rLayout.addComponent(recipientList);
// rLayout.setMargin(true);
// clearWindow();
// window.addComponent(rLayout);
// }
//
// public void setTemplateList()
// {
// TemplateList templateList = new TemplateList();
// VerticalLayout tlLayout = new VerticalLayout();
// tlLayout.addComponent(templateList);
// tlLayout.setMargin(true);
// clearWindow();
// window.addComponent(tlLayout);
// }
//
// public void startWizard()
// {
// SetupWizardComponent wb = new SetupWizardComponent();
// window.addComponent(wb);
// }
//
// public MenuBar getMenu()
// {
// return menu;
// }
//
// public void setMenu(MenuBar menu)
// {
// this.menu = menu;
// }
//
// @Override
// public void close()
// {
// super.close();
// // Registers a shutdown hook for the Neo4j and index service instances
// // so that it shuts down nicely when the VM exits (even if you
// // "Ctrl-C" the running example before it's completed)
// Runtime.getRuntime().addShutdownHook(new Thread()
// {
// @Override
// public void run()
// {
// Logger.getLogger(MainApp.class).info("Shutdown hook called");
// ConnectionFactory.getDatabase().shutdown();
// }
// });
//
// }
// }
// Path: pigeon-web/src/main/java/com/trivago/mail/pigeon/web/components/menu/MenuBar.java
import com.trivago.mail.pigeon.web.MainApp;
import java.lang.reflect.InvocationTargetException;
/**
* Copyright (C) 2011-2012 trivago GmbH <[email protected]>, <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.trivago.mail.pigeon.web.components.menu;
public class MenuBar extends com.vaadin.ui.MenuBar
{
| private MainApp app;
|
bonigarcia/selenium-jupiter | src/main/java/io/github/bonigarcia/seljup/BrowserBuilder.java | // Path: src/main/java/io/github/bonigarcia/seljup/BrowsersTemplate.java
// public static class Browser {
// String type;
// String version;
// String remoteUrl;
// String[] arguments;
// String[] preferences;
// Object capabilities;
//
// public Browser(String type, String version, String remoteUrl,
// String[] arguments, String[] preferences, Object capabilities) {
// this.type = type;
// this.version = version;
// this.remoteUrl = remoteUrl;
// this.arguments = arguments;
// this.preferences = preferences;
// this.capabilities = capabilities;
// }
//
// public Browser() {
// }
//
// public String getType() {
// return type;
// }
//
// public String getVersion() {
// return version;
// }
//
// public String getRemoteUrl() {
// return remoteUrl;
// }
//
// public void setRemoteUrl(String url) {
// this.remoteUrl = url;
// }
//
// public String[] getArguments() {
// return arguments;
// }
//
// public void setArguments(String[] arguments) {
// this.arguments = arguments;
// }
//
// public String[] getPreferences() {
// return preferences;
// }
//
// public void setPreferences(String[] preferences) {
// this.preferences = preferences;
// }
//
// public Object getCapabilities() {
// return capabilities;
// }
//
// public void setCapabilities(Object capabilities) {
// this.capabilities = capabilities;
// }
//
// public BrowserType toBrowserType() {
// return toBrowserType(getType());
// }
//
// public static BrowserType toBrowserType(String browser) {
// return BrowserType.valueOf(
// browser.replace(IN_DOCKER, "").replace(IN_SELENIDE, "")
// .replace("-", "_").toUpperCase(ROOT));
// }
//
// public boolean isAndroidBrowser() {
// return toBrowserType() == CHROME_MOBILE;
// }
//
// public boolean isDockerBrowser() {
// return getType().contains(IN_DOCKER);
// }
//
// public boolean isInSelenide() {
// return getType().contains(IN_SELENIDE);
// }
//
// @Override
// public String toString() {
// String versionMessage = getVersion() != null
// ? ", version=" + getVersion()
// : "";
// return "Browser [type=" + getType() + versionMessage + "]";
// }
//
// }
| import com.google.gson.internal.LinkedTreeMap;
import io.github.bonigarcia.seljup.BrowsersTemplate.Browser;
| public static BrowserBuilder safariInDocker() {
return new BrowserBuilder("safari-in-docker");
}
public BrowserBuilder version(String version) {
this.version = version;
return this;
}
public BrowserBuilder remoteUrl(String url) {
this.remoteUrl = url;
return this;
}
public BrowserBuilder arguments(String[] arguments) {
this.arguments = arguments;
return this;
}
public BrowserBuilder preferences(String[] preferences) {
this.preferences = preferences;
return this;
}
public BrowserBuilder capabilities(
LinkedTreeMap<String, String> capabilities) {
this.capabilities = capabilities;
return this;
}
| // Path: src/main/java/io/github/bonigarcia/seljup/BrowsersTemplate.java
// public static class Browser {
// String type;
// String version;
// String remoteUrl;
// String[] arguments;
// String[] preferences;
// Object capabilities;
//
// public Browser(String type, String version, String remoteUrl,
// String[] arguments, String[] preferences, Object capabilities) {
// this.type = type;
// this.version = version;
// this.remoteUrl = remoteUrl;
// this.arguments = arguments;
// this.preferences = preferences;
// this.capabilities = capabilities;
// }
//
// public Browser() {
// }
//
// public String getType() {
// return type;
// }
//
// public String getVersion() {
// return version;
// }
//
// public String getRemoteUrl() {
// return remoteUrl;
// }
//
// public void setRemoteUrl(String url) {
// this.remoteUrl = url;
// }
//
// public String[] getArguments() {
// return arguments;
// }
//
// public void setArguments(String[] arguments) {
// this.arguments = arguments;
// }
//
// public String[] getPreferences() {
// return preferences;
// }
//
// public void setPreferences(String[] preferences) {
// this.preferences = preferences;
// }
//
// public Object getCapabilities() {
// return capabilities;
// }
//
// public void setCapabilities(Object capabilities) {
// this.capabilities = capabilities;
// }
//
// public BrowserType toBrowserType() {
// return toBrowserType(getType());
// }
//
// public static BrowserType toBrowserType(String browser) {
// return BrowserType.valueOf(
// browser.replace(IN_DOCKER, "").replace(IN_SELENIDE, "")
// .replace("-", "_").toUpperCase(ROOT));
// }
//
// public boolean isAndroidBrowser() {
// return toBrowserType() == CHROME_MOBILE;
// }
//
// public boolean isDockerBrowser() {
// return getType().contains(IN_DOCKER);
// }
//
// public boolean isInSelenide() {
// return getType().contains(IN_SELENIDE);
// }
//
// @Override
// public String toString() {
// String versionMessage = getVersion() != null
// ? ", version=" + getVersion()
// : "";
// return "Browser [type=" + getType() + versionMessage + "]";
// }
//
// }
// Path: src/main/java/io/github/bonigarcia/seljup/BrowserBuilder.java
import com.google.gson.internal.LinkedTreeMap;
import io.github.bonigarcia.seljup.BrowsersTemplate.Browser;
public static BrowserBuilder safariInDocker() {
return new BrowserBuilder("safari-in-docker");
}
public BrowserBuilder version(String version) {
this.version = version;
return this;
}
public BrowserBuilder remoteUrl(String url) {
this.remoteUrl = url;
return this;
}
public BrowserBuilder arguments(String[] arguments) {
this.arguments = arguments;
return this;
}
public BrowserBuilder preferences(String[] preferences) {
this.preferences = preferences;
return this;
}
public BrowserBuilder capabilities(
LinkedTreeMap<String, String> capabilities) {
this.capabilities = capabilities;
return this;
}
| public Browser build() {
|
bonigarcia/selenium-jupiter | src/main/java/io/github/bonigarcia/seljup/config/Config.java | // Path: src/main/java/io/github/bonigarcia/seljup/OutputHandler.java
// public static final String BASE64_AND_PNG_KEY = "base64andpng";
//
// Path: src/main/java/io/github/bonigarcia/seljup/OutputHandler.java
// public static final String BASE64_KEY = "base64";
//
// Path: src/main/java/io/github/bonigarcia/seljup/OutputHandler.java
// public static final String PNG_KEY = "png";
//
// Path: src/main/java/io/github/bonigarcia/seljup/OutputHandler.java
// public static final String SUREFIRE_REPORTS_KEY = "surefire-reports";
//
// Path: src/main/java/io/github/bonigarcia/seljup/SeleniumJupiterException.java
// public class SeleniumJupiterException extends RuntimeException {
//
// private static final long serialVersionUID = -7026228903533825338L;
//
// public SeleniumJupiterException(String message) {
// super(message);
// }
//
// public SeleniumJupiterException(Throwable cause) {
// super(cause);
// }
//
// public SeleniumJupiterException(String message, Throwable cause) {
// super(message, cause);
// }
//
// }
| import io.github.bonigarcia.wdm.WebDriverManager;
import static io.github.bonigarcia.seljup.OutputHandler.BASE64_AND_PNG_KEY;
import static io.github.bonigarcia.seljup.OutputHandler.BASE64_KEY;
import static io.github.bonigarcia.seljup.OutputHandler.PNG_KEY;
import static io.github.bonigarcia.seljup.OutputHandler.SUREFIRE_REPORTS_KEY;
import static java.lang.invoke.MethodHandles.lookup;
import static org.slf4j.LoggerFactory.getLogger;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.util.Properties;
import org.slf4j.Logger;
import io.github.bonigarcia.seljup.SeleniumJupiterException; |
private <T> T resolve(ConfigKey<T> configKey) {
String strValue = null;
String name = configKey.getName();
T tValue = configKey.getValue();
Class<T> type = configKey.getType();
strValue = System.getenv(name.toUpperCase().replace(".", "_"));
if (strValue == null) {
strValue = System.getProperty(name);
}
if (strValue == null && tValue != null) {
return tValue;
}
if (strValue == null) {
strValue = getProperty(name);
}
return parse(type, strValue);
}
@SuppressWarnings("unchecked")
private <T> T parse(Class<T> type, String strValue) {
T output = null;
if (type.equals(String.class)) {
output = (T) strValue;
} else if (type.equals(Integer.class)) {
output = (T) Integer.valueOf(strValue);
} else if (type.equals(Boolean.class)) {
output = (T) Boolean.valueOf(strValue);
} else { | // Path: src/main/java/io/github/bonigarcia/seljup/OutputHandler.java
// public static final String BASE64_AND_PNG_KEY = "base64andpng";
//
// Path: src/main/java/io/github/bonigarcia/seljup/OutputHandler.java
// public static final String BASE64_KEY = "base64";
//
// Path: src/main/java/io/github/bonigarcia/seljup/OutputHandler.java
// public static final String PNG_KEY = "png";
//
// Path: src/main/java/io/github/bonigarcia/seljup/OutputHandler.java
// public static final String SUREFIRE_REPORTS_KEY = "surefire-reports";
//
// Path: src/main/java/io/github/bonigarcia/seljup/SeleniumJupiterException.java
// public class SeleniumJupiterException extends RuntimeException {
//
// private static final long serialVersionUID = -7026228903533825338L;
//
// public SeleniumJupiterException(String message) {
// super(message);
// }
//
// public SeleniumJupiterException(Throwable cause) {
// super(cause);
// }
//
// public SeleniumJupiterException(String message, Throwable cause) {
// super(message, cause);
// }
//
// }
// Path: src/main/java/io/github/bonigarcia/seljup/config/Config.java
import io.github.bonigarcia.wdm.WebDriverManager;
import static io.github.bonigarcia.seljup.OutputHandler.BASE64_AND_PNG_KEY;
import static io.github.bonigarcia.seljup.OutputHandler.BASE64_KEY;
import static io.github.bonigarcia.seljup.OutputHandler.PNG_KEY;
import static io.github.bonigarcia.seljup.OutputHandler.SUREFIRE_REPORTS_KEY;
import static java.lang.invoke.MethodHandles.lookup;
import static org.slf4j.LoggerFactory.getLogger;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.util.Properties;
import org.slf4j.Logger;
import io.github.bonigarcia.seljup.SeleniumJupiterException;
private <T> T resolve(ConfigKey<T> configKey) {
String strValue = null;
String name = configKey.getName();
T tValue = configKey.getValue();
Class<T> type = configKey.getType();
strValue = System.getenv(name.toUpperCase().replace(".", "_"));
if (strValue == null) {
strValue = System.getProperty(name);
}
if (strValue == null && tValue != null) {
return tValue;
}
if (strValue == null) {
strValue = getProperty(name);
}
return parse(type, strValue);
}
@SuppressWarnings("unchecked")
private <T> T parse(Class<T> type, String strValue) {
T output = null;
if (type.equals(String.class)) {
output = (T) strValue;
} else if (type.equals(Integer.class)) {
output = (T) Integer.valueOf(strValue);
} else if (type.equals(Boolean.class)) {
output = (T) Boolean.valueOf(strValue);
} else { | throw new SeleniumJupiterException( |
bonigarcia/selenium-jupiter | src/main/java/io/github/bonigarcia/seljup/config/Config.java | // Path: src/main/java/io/github/bonigarcia/seljup/OutputHandler.java
// public static final String BASE64_AND_PNG_KEY = "base64andpng";
//
// Path: src/main/java/io/github/bonigarcia/seljup/OutputHandler.java
// public static final String BASE64_KEY = "base64";
//
// Path: src/main/java/io/github/bonigarcia/seljup/OutputHandler.java
// public static final String PNG_KEY = "png";
//
// Path: src/main/java/io/github/bonigarcia/seljup/OutputHandler.java
// public static final String SUREFIRE_REPORTS_KEY = "surefire-reports";
//
// Path: src/main/java/io/github/bonigarcia/seljup/SeleniumJupiterException.java
// public class SeleniumJupiterException extends RuntimeException {
//
// private static final long serialVersionUID = -7026228903533825338L;
//
// public SeleniumJupiterException(String message) {
// super(message);
// }
//
// public SeleniumJupiterException(Throwable cause) {
// super(cause);
// }
//
// public SeleniumJupiterException(String message, Throwable cause) {
// super(message, cause);
// }
//
// }
| import io.github.bonigarcia.wdm.WebDriverManager;
import static io.github.bonigarcia.seljup.OutputHandler.BASE64_AND_PNG_KEY;
import static io.github.bonigarcia.seljup.OutputHandler.BASE64_KEY;
import static io.github.bonigarcia.seljup.OutputHandler.PNG_KEY;
import static io.github.bonigarcia.seljup.OutputHandler.SUREFIRE_REPORTS_KEY;
import static java.lang.invoke.MethodHandles.lookup;
import static org.slf4j.LoggerFactory.getLogger;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.util.Properties;
import org.slf4j.Logger;
import io.github.bonigarcia.seljup.SeleniumJupiterException; | return manager;
}
public void setManager(WebDriverManager manager) {
this.manager = manager;
}
// Readable API methods
public void enableVnc() {
setVnc(true);
}
public void enableScreenshot() {
setScreenshot(true);
}
public void enableRecording() {
setRecording(true);
}
public void enableRecordingWhenFailure() {
setRecordingWhenFailure(true);
}
public void enableScreenshotWhenFailure() {
setScreenshotWhenFailure(true);
}
public void useSurefireOutputFolder() { | // Path: src/main/java/io/github/bonigarcia/seljup/OutputHandler.java
// public static final String BASE64_AND_PNG_KEY = "base64andpng";
//
// Path: src/main/java/io/github/bonigarcia/seljup/OutputHandler.java
// public static final String BASE64_KEY = "base64";
//
// Path: src/main/java/io/github/bonigarcia/seljup/OutputHandler.java
// public static final String PNG_KEY = "png";
//
// Path: src/main/java/io/github/bonigarcia/seljup/OutputHandler.java
// public static final String SUREFIRE_REPORTS_KEY = "surefire-reports";
//
// Path: src/main/java/io/github/bonigarcia/seljup/SeleniumJupiterException.java
// public class SeleniumJupiterException extends RuntimeException {
//
// private static final long serialVersionUID = -7026228903533825338L;
//
// public SeleniumJupiterException(String message) {
// super(message);
// }
//
// public SeleniumJupiterException(Throwable cause) {
// super(cause);
// }
//
// public SeleniumJupiterException(String message, Throwable cause) {
// super(message, cause);
// }
//
// }
// Path: src/main/java/io/github/bonigarcia/seljup/config/Config.java
import io.github.bonigarcia.wdm.WebDriverManager;
import static io.github.bonigarcia.seljup.OutputHandler.BASE64_AND_PNG_KEY;
import static io.github.bonigarcia.seljup.OutputHandler.BASE64_KEY;
import static io.github.bonigarcia.seljup.OutputHandler.PNG_KEY;
import static io.github.bonigarcia.seljup.OutputHandler.SUREFIRE_REPORTS_KEY;
import static java.lang.invoke.MethodHandles.lookup;
import static org.slf4j.LoggerFactory.getLogger;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.util.Properties;
import org.slf4j.Logger;
import io.github.bonigarcia.seljup.SeleniumJupiterException;
return manager;
}
public void setManager(WebDriverManager manager) {
this.manager = manager;
}
// Readable API methods
public void enableVnc() {
setVnc(true);
}
public void enableScreenshot() {
setScreenshot(true);
}
public void enableRecording() {
setRecording(true);
}
public void enableRecordingWhenFailure() {
setRecordingWhenFailure(true);
}
public void enableScreenshotWhenFailure() {
setScreenshotWhenFailure(true);
}
public void useSurefireOutputFolder() { | setOutputFolder(SUREFIRE_REPORTS_KEY); |
bonigarcia/selenium-jupiter | src/main/java/io/github/bonigarcia/seljup/config/Config.java | // Path: src/main/java/io/github/bonigarcia/seljup/OutputHandler.java
// public static final String BASE64_AND_PNG_KEY = "base64andpng";
//
// Path: src/main/java/io/github/bonigarcia/seljup/OutputHandler.java
// public static final String BASE64_KEY = "base64";
//
// Path: src/main/java/io/github/bonigarcia/seljup/OutputHandler.java
// public static final String PNG_KEY = "png";
//
// Path: src/main/java/io/github/bonigarcia/seljup/OutputHandler.java
// public static final String SUREFIRE_REPORTS_KEY = "surefire-reports";
//
// Path: src/main/java/io/github/bonigarcia/seljup/SeleniumJupiterException.java
// public class SeleniumJupiterException extends RuntimeException {
//
// private static final long serialVersionUID = -7026228903533825338L;
//
// public SeleniumJupiterException(String message) {
// super(message);
// }
//
// public SeleniumJupiterException(Throwable cause) {
// super(cause);
// }
//
// public SeleniumJupiterException(String message, Throwable cause) {
// super(message, cause);
// }
//
// }
| import io.github.bonigarcia.wdm.WebDriverManager;
import static io.github.bonigarcia.seljup.OutputHandler.BASE64_AND_PNG_KEY;
import static io.github.bonigarcia.seljup.OutputHandler.BASE64_KEY;
import static io.github.bonigarcia.seljup.OutputHandler.PNG_KEY;
import static io.github.bonigarcia.seljup.OutputHandler.SUREFIRE_REPORTS_KEY;
import static java.lang.invoke.MethodHandles.lookup;
import static org.slf4j.LoggerFactory.getLogger;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.util.Properties;
import org.slf4j.Logger;
import io.github.bonigarcia.seljup.SeleniumJupiterException; | this.manager = manager;
}
// Readable API methods
public void enableVnc() {
setVnc(true);
}
public void enableScreenshot() {
setScreenshot(true);
}
public void enableRecording() {
setRecording(true);
}
public void enableRecordingWhenFailure() {
setRecordingWhenFailure(true);
}
public void enableScreenshotWhenFailure() {
setScreenshotWhenFailure(true);
}
public void useSurefireOutputFolder() {
setOutputFolder(SUREFIRE_REPORTS_KEY);
}
public void takeScreenshotAsBase64() { | // Path: src/main/java/io/github/bonigarcia/seljup/OutputHandler.java
// public static final String BASE64_AND_PNG_KEY = "base64andpng";
//
// Path: src/main/java/io/github/bonigarcia/seljup/OutputHandler.java
// public static final String BASE64_KEY = "base64";
//
// Path: src/main/java/io/github/bonigarcia/seljup/OutputHandler.java
// public static final String PNG_KEY = "png";
//
// Path: src/main/java/io/github/bonigarcia/seljup/OutputHandler.java
// public static final String SUREFIRE_REPORTS_KEY = "surefire-reports";
//
// Path: src/main/java/io/github/bonigarcia/seljup/SeleniumJupiterException.java
// public class SeleniumJupiterException extends RuntimeException {
//
// private static final long serialVersionUID = -7026228903533825338L;
//
// public SeleniumJupiterException(String message) {
// super(message);
// }
//
// public SeleniumJupiterException(Throwable cause) {
// super(cause);
// }
//
// public SeleniumJupiterException(String message, Throwable cause) {
// super(message, cause);
// }
//
// }
// Path: src/main/java/io/github/bonigarcia/seljup/config/Config.java
import io.github.bonigarcia.wdm.WebDriverManager;
import static io.github.bonigarcia.seljup.OutputHandler.BASE64_AND_PNG_KEY;
import static io.github.bonigarcia.seljup.OutputHandler.BASE64_KEY;
import static io.github.bonigarcia.seljup.OutputHandler.PNG_KEY;
import static io.github.bonigarcia.seljup.OutputHandler.SUREFIRE_REPORTS_KEY;
import static java.lang.invoke.MethodHandles.lookup;
import static org.slf4j.LoggerFactory.getLogger;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.util.Properties;
import org.slf4j.Logger;
import io.github.bonigarcia.seljup.SeleniumJupiterException;
this.manager = manager;
}
// Readable API methods
public void enableVnc() {
setVnc(true);
}
public void enableScreenshot() {
setScreenshot(true);
}
public void enableRecording() {
setRecording(true);
}
public void enableRecordingWhenFailure() {
setRecordingWhenFailure(true);
}
public void enableScreenshotWhenFailure() {
setScreenshotWhenFailure(true);
}
public void useSurefireOutputFolder() {
setOutputFolder(SUREFIRE_REPORTS_KEY);
}
public void takeScreenshotAsBase64() { | setScreenshotFormat(BASE64_KEY); |
bonigarcia/selenium-jupiter | src/main/java/io/github/bonigarcia/seljup/config/Config.java | // Path: src/main/java/io/github/bonigarcia/seljup/OutputHandler.java
// public static final String BASE64_AND_PNG_KEY = "base64andpng";
//
// Path: src/main/java/io/github/bonigarcia/seljup/OutputHandler.java
// public static final String BASE64_KEY = "base64";
//
// Path: src/main/java/io/github/bonigarcia/seljup/OutputHandler.java
// public static final String PNG_KEY = "png";
//
// Path: src/main/java/io/github/bonigarcia/seljup/OutputHandler.java
// public static final String SUREFIRE_REPORTS_KEY = "surefire-reports";
//
// Path: src/main/java/io/github/bonigarcia/seljup/SeleniumJupiterException.java
// public class SeleniumJupiterException extends RuntimeException {
//
// private static final long serialVersionUID = -7026228903533825338L;
//
// public SeleniumJupiterException(String message) {
// super(message);
// }
//
// public SeleniumJupiterException(Throwable cause) {
// super(cause);
// }
//
// public SeleniumJupiterException(String message, Throwable cause) {
// super(message, cause);
// }
//
// }
| import io.github.bonigarcia.wdm.WebDriverManager;
import static io.github.bonigarcia.seljup.OutputHandler.BASE64_AND_PNG_KEY;
import static io.github.bonigarcia.seljup.OutputHandler.BASE64_KEY;
import static io.github.bonigarcia.seljup.OutputHandler.PNG_KEY;
import static io.github.bonigarcia.seljup.OutputHandler.SUREFIRE_REPORTS_KEY;
import static java.lang.invoke.MethodHandles.lookup;
import static org.slf4j.LoggerFactory.getLogger;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.util.Properties;
import org.slf4j.Logger;
import io.github.bonigarcia.seljup.SeleniumJupiterException; |
public void enableVnc() {
setVnc(true);
}
public void enableScreenshot() {
setScreenshot(true);
}
public void enableRecording() {
setRecording(true);
}
public void enableRecordingWhenFailure() {
setRecordingWhenFailure(true);
}
public void enableScreenshotWhenFailure() {
setScreenshotWhenFailure(true);
}
public void useSurefireOutputFolder() {
setOutputFolder(SUREFIRE_REPORTS_KEY);
}
public void takeScreenshotAsBase64() {
setScreenshotFormat(BASE64_KEY);
}
public void takeScreenshotAsPng() { | // Path: src/main/java/io/github/bonigarcia/seljup/OutputHandler.java
// public static final String BASE64_AND_PNG_KEY = "base64andpng";
//
// Path: src/main/java/io/github/bonigarcia/seljup/OutputHandler.java
// public static final String BASE64_KEY = "base64";
//
// Path: src/main/java/io/github/bonigarcia/seljup/OutputHandler.java
// public static final String PNG_KEY = "png";
//
// Path: src/main/java/io/github/bonigarcia/seljup/OutputHandler.java
// public static final String SUREFIRE_REPORTS_KEY = "surefire-reports";
//
// Path: src/main/java/io/github/bonigarcia/seljup/SeleniumJupiterException.java
// public class SeleniumJupiterException extends RuntimeException {
//
// private static final long serialVersionUID = -7026228903533825338L;
//
// public SeleniumJupiterException(String message) {
// super(message);
// }
//
// public SeleniumJupiterException(Throwable cause) {
// super(cause);
// }
//
// public SeleniumJupiterException(String message, Throwable cause) {
// super(message, cause);
// }
//
// }
// Path: src/main/java/io/github/bonigarcia/seljup/config/Config.java
import io.github.bonigarcia.wdm.WebDriverManager;
import static io.github.bonigarcia.seljup.OutputHandler.BASE64_AND_PNG_KEY;
import static io.github.bonigarcia.seljup.OutputHandler.BASE64_KEY;
import static io.github.bonigarcia.seljup.OutputHandler.PNG_KEY;
import static io.github.bonigarcia.seljup.OutputHandler.SUREFIRE_REPORTS_KEY;
import static java.lang.invoke.MethodHandles.lookup;
import static org.slf4j.LoggerFactory.getLogger;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.util.Properties;
import org.slf4j.Logger;
import io.github.bonigarcia.seljup.SeleniumJupiterException;
public void enableVnc() {
setVnc(true);
}
public void enableScreenshot() {
setScreenshot(true);
}
public void enableRecording() {
setRecording(true);
}
public void enableRecordingWhenFailure() {
setRecordingWhenFailure(true);
}
public void enableScreenshotWhenFailure() {
setScreenshotWhenFailure(true);
}
public void useSurefireOutputFolder() {
setOutputFolder(SUREFIRE_REPORTS_KEY);
}
public void takeScreenshotAsBase64() {
setScreenshotFormat(BASE64_KEY);
}
public void takeScreenshotAsPng() { | setScreenshotFormat(PNG_KEY); |
bonigarcia/selenium-jupiter | src/main/java/io/github/bonigarcia/seljup/config/Config.java | // Path: src/main/java/io/github/bonigarcia/seljup/OutputHandler.java
// public static final String BASE64_AND_PNG_KEY = "base64andpng";
//
// Path: src/main/java/io/github/bonigarcia/seljup/OutputHandler.java
// public static final String BASE64_KEY = "base64";
//
// Path: src/main/java/io/github/bonigarcia/seljup/OutputHandler.java
// public static final String PNG_KEY = "png";
//
// Path: src/main/java/io/github/bonigarcia/seljup/OutputHandler.java
// public static final String SUREFIRE_REPORTS_KEY = "surefire-reports";
//
// Path: src/main/java/io/github/bonigarcia/seljup/SeleniumJupiterException.java
// public class SeleniumJupiterException extends RuntimeException {
//
// private static final long serialVersionUID = -7026228903533825338L;
//
// public SeleniumJupiterException(String message) {
// super(message);
// }
//
// public SeleniumJupiterException(Throwable cause) {
// super(cause);
// }
//
// public SeleniumJupiterException(String message, Throwable cause) {
// super(message, cause);
// }
//
// }
| import io.github.bonigarcia.wdm.WebDriverManager;
import static io.github.bonigarcia.seljup.OutputHandler.BASE64_AND_PNG_KEY;
import static io.github.bonigarcia.seljup.OutputHandler.BASE64_KEY;
import static io.github.bonigarcia.seljup.OutputHandler.PNG_KEY;
import static io.github.bonigarcia.seljup.OutputHandler.SUREFIRE_REPORTS_KEY;
import static java.lang.invoke.MethodHandles.lookup;
import static org.slf4j.LoggerFactory.getLogger;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.util.Properties;
import org.slf4j.Logger;
import io.github.bonigarcia.seljup.SeleniumJupiterException; |
public void enableScreenshot() {
setScreenshot(true);
}
public void enableRecording() {
setRecording(true);
}
public void enableRecordingWhenFailure() {
setRecordingWhenFailure(true);
}
public void enableScreenshotWhenFailure() {
setScreenshotWhenFailure(true);
}
public void useSurefireOutputFolder() {
setOutputFolder(SUREFIRE_REPORTS_KEY);
}
public void takeScreenshotAsBase64() {
setScreenshotFormat(BASE64_KEY);
}
public void takeScreenshotAsPng() {
setScreenshotFormat(PNG_KEY);
}
public void takeScreenshotAsBase64AndPng() { | // Path: src/main/java/io/github/bonigarcia/seljup/OutputHandler.java
// public static final String BASE64_AND_PNG_KEY = "base64andpng";
//
// Path: src/main/java/io/github/bonigarcia/seljup/OutputHandler.java
// public static final String BASE64_KEY = "base64";
//
// Path: src/main/java/io/github/bonigarcia/seljup/OutputHandler.java
// public static final String PNG_KEY = "png";
//
// Path: src/main/java/io/github/bonigarcia/seljup/OutputHandler.java
// public static final String SUREFIRE_REPORTS_KEY = "surefire-reports";
//
// Path: src/main/java/io/github/bonigarcia/seljup/SeleniumJupiterException.java
// public class SeleniumJupiterException extends RuntimeException {
//
// private static final long serialVersionUID = -7026228903533825338L;
//
// public SeleniumJupiterException(String message) {
// super(message);
// }
//
// public SeleniumJupiterException(Throwable cause) {
// super(cause);
// }
//
// public SeleniumJupiterException(String message, Throwable cause) {
// super(message, cause);
// }
//
// }
// Path: src/main/java/io/github/bonigarcia/seljup/config/Config.java
import io.github.bonigarcia.wdm.WebDriverManager;
import static io.github.bonigarcia.seljup.OutputHandler.BASE64_AND_PNG_KEY;
import static io.github.bonigarcia.seljup.OutputHandler.BASE64_KEY;
import static io.github.bonigarcia.seljup.OutputHandler.PNG_KEY;
import static io.github.bonigarcia.seljup.OutputHandler.SUREFIRE_REPORTS_KEY;
import static java.lang.invoke.MethodHandles.lookup;
import static org.slf4j.LoggerFactory.getLogger;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.util.Properties;
import org.slf4j.Logger;
import io.github.bonigarcia.seljup.SeleniumJupiterException;
public void enableScreenshot() {
setScreenshot(true);
}
public void enableRecording() {
setRecording(true);
}
public void enableRecordingWhenFailure() {
setRecordingWhenFailure(true);
}
public void enableScreenshotWhenFailure() {
setScreenshotWhenFailure(true);
}
public void useSurefireOutputFolder() {
setOutputFolder(SUREFIRE_REPORTS_KEY);
}
public void takeScreenshotAsBase64() {
setScreenshotFormat(BASE64_KEY);
}
public void takeScreenshotAsPng() {
setScreenshotFormat(PNG_KEY);
}
public void takeScreenshotAsBase64AndPng() { | setScreenshotFormat(BASE64_AND_PNG_KEY); |
chenmins/objector | objector/src/main/java/org/chenmin/open/objector/annotation/Column.java | // Path: objector/src/main/java/org/chenmin/open/objector/ColumnTypeObject.java
// public enum ColumnTypeObject {
// STRING, INTEGER, BOOLEAN, DOUBLE, BINARY;
// }
| import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.chenmin.open.objector.ColumnTypeObject;
| package org.chenmin.open.objector.annotation;
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD})
@Inherited
public @interface Column {
/**
* Controls the actual kind name used in the datastore.
*/
String value() default "";
| // Path: objector/src/main/java/org/chenmin/open/objector/ColumnTypeObject.java
// public enum ColumnTypeObject {
// STRING, INTEGER, BOOLEAN, DOUBLE, BINARY;
// }
// Path: objector/src/main/java/org/chenmin/open/objector/annotation/Column.java
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.chenmin.open.objector.ColumnTypeObject;
package org.chenmin.open.objector.annotation;
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD})
@Inherited
public @interface Column {
/**
* Controls the actual kind name used in the datastore.
*/
String value() default "";
| ColumnTypeObject type() default ColumnTypeObject.STRING;
|
chenmins/objector | objector/src/main/java/org/chenmin/open/objector/annotation/Key.java | // Path: objector/src/main/java/org/chenmin/open/objector/PrimaryKeyTypeObject.java
// public enum PrimaryKeyTypeObject {
// STRING, INTEGER, BINARY;
// }
| import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.chenmin.open.objector.PrimaryKeyTypeObject;
| package org.chenmin.open.objector.annotation;
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD})
@Inherited
public @interface Key {
/**
* Controls the actual kind name used in the datastore.
*/
String value() default "";
| // Path: objector/src/main/java/org/chenmin/open/objector/PrimaryKeyTypeObject.java
// public enum PrimaryKeyTypeObject {
// STRING, INTEGER, BINARY;
// }
// Path: objector/src/main/java/org/chenmin/open/objector/annotation/Key.java
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.chenmin.open.objector.PrimaryKeyTypeObject;
package org.chenmin.open.objector.annotation;
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD})
@Inherited
public @interface Key {
/**
* Controls the actual kind name used in the datastore.
*/
String value() default "";
| PrimaryKeyTypeObject type() default PrimaryKeyTypeObject.STRING;
|
chenmins/objector | objector-test/src/test/java/org/chenmin/open/objector/test/Custom.java | // Path: objector-ots/src/main/java/org/chenmin/open/objector/BooleanIntrospector.java
// public class BooleanIntrospector implements BeanIntrospector{
// @Override
// public void introspect(IntrospectionContext icontext) throws IntrospectionException {
// for (Method m : icontext.getTargetClass().getMethods()) {
// if (m.getName().startsWith("is") && Boolean.class.equals(m.getReturnType())) {
// String propertyName = getPropertyName(m);
// PropertyDescriptor pd = icontext.getPropertyDescriptor(propertyName);
//
// if (pd == null)
// icontext.addPropertyDescriptor(new PropertyDescriptor(propertyName, m, getWriteMethod(icontext.getTargetClass(), propertyName)));
// else if (pd.getReadMethod() == null)
// pd.setReadMethod(m);
//
// }
// }
// }
//
// private String getPropertyName(Method m){
// return WordUtils.uncapitalize(m.getName().substring(2, m.getName().length()));
// }
//
// private Method getWriteMethod(Class<?> clazz, String propertyName){
// try {
// return clazz.getMethod("get" + WordUtils.capitalize(propertyName));
// } catch (NoSuchMethodException e) {
// return null;
// }
// }
// }
| import org.apache.commons.beanutils.BeanIntrospector;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.BeanUtilsBean;
import org.apache.commons.beanutils.DynaBean;
import org.apache.commons.beanutils.DynaProperty;
import org.apache.commons.beanutils.WrapDynaBean;
import org.chenmin.open.objector.BooleanIntrospector;
| package org.chenmin.open.objector.test;
public class Custom {
public static class Test {
private Integer a;
private Boolean b;
private Boolean c;
public Integer getA() {
return a;
}
public void setA(Integer a) {
this.a = a;
}
public Boolean getB() {
return b;
}
public void setB(Boolean b) {
this.b = b;
}
public Boolean isC() {
return c;
}
public void setC(Boolean c) {
this.c = c;
}
}
public static void main(String[] args) {
try {
| // Path: objector-ots/src/main/java/org/chenmin/open/objector/BooleanIntrospector.java
// public class BooleanIntrospector implements BeanIntrospector{
// @Override
// public void introspect(IntrospectionContext icontext) throws IntrospectionException {
// for (Method m : icontext.getTargetClass().getMethods()) {
// if (m.getName().startsWith("is") && Boolean.class.equals(m.getReturnType())) {
// String propertyName = getPropertyName(m);
// PropertyDescriptor pd = icontext.getPropertyDescriptor(propertyName);
//
// if (pd == null)
// icontext.addPropertyDescriptor(new PropertyDescriptor(propertyName, m, getWriteMethod(icontext.getTargetClass(), propertyName)));
// else if (pd.getReadMethod() == null)
// pd.setReadMethod(m);
//
// }
// }
// }
//
// private String getPropertyName(Method m){
// return WordUtils.uncapitalize(m.getName().substring(2, m.getName().length()));
// }
//
// private Method getWriteMethod(Class<?> clazz, String propertyName){
// try {
// return clazz.getMethod("get" + WordUtils.capitalize(propertyName));
// } catch (NoSuchMethodException e) {
// return null;
// }
// }
// }
// Path: objector-test/src/test/java/org/chenmin/open/objector/test/Custom.java
import org.apache.commons.beanutils.BeanIntrospector;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.BeanUtilsBean;
import org.apache.commons.beanutils.DynaBean;
import org.apache.commons.beanutils.DynaProperty;
import org.apache.commons.beanutils.WrapDynaBean;
import org.chenmin.open.objector.BooleanIntrospector;
package org.chenmin.open.objector.test;
public class Custom {
public static class Test {
private Integer a;
private Boolean b;
private Boolean c;
public Integer getA() {
return a;
}
public void setA(Integer a) {
this.a = a;
}
public Boolean getB() {
return b;
}
public void setB(Boolean b) {
this.b = b;
}
public Boolean isC() {
return c;
}
public void setC(Boolean c) {
this.c = c;
}
}
public static void main(String[] args) {
try {
| BeanIntrospector a = new BooleanIntrospector();
|
android10/arrow | src/main/java/com/fernandocejas/arrow/collections/AbstractIterator.java | // Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static void checkState(boolean expression) {
// if (!expression) {
// throw new IllegalStateException();
// }
// }
| import java.util.NoSuchElementException;
import static com.fernandocejas.arrow.checks.Preconditions.checkState; | /**
* Copyright (C) 2007 The Guava Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.fernandocejas.arrow.collections;
/**
* This class provides a skeletal implementation of the {@code Iterator}
* interface, to make this interface easier to implement for certain types of
* data sources.
*
* <p>{@code Iterator} requires its implementations to support querying the
* end-of-data status without changing the iterator's state, using the {@link
* #hasNext} method. But many data sources, such as {@link
* java.io.Reader#read()}, do not expose this information; the only way to
* discover whether there is any data left is by trying to retrieve it. These
* types of data sources are ordinarily difficult to write iterators for. But
* using this class, one must implement only the {@link #computeNext} method,
* and invoke the {@link #endOfData} method when appropriate.
*
* <p>Another example is an iterator that skips over null elements in a backing
* iterator. This could be implemented as: <pre> {@code
*
* public static Iterator<String> skipNulls(final Iterator<String> in) {
* return new AbstractIterator<String>() {
* protected String computeNext() {
* while (in.hasNext()) {
* String s = in.next();
* if (s != null) {
* return s;
* }
* }
* return endOfData();
* }
* };
* }}</pre>
*
* <p>This class supports iterators that include null elements.
*
* @author Kevin Bourrillion
* @since 2.0 (imported from Google Collections Library)
*
* <p><b>This class contains code derived from <a href="https://github.com/google/guava">Google
* Guava</a></b>
*/
public abstract class AbstractIterator<T> extends UnmodifiableIterator<T> {
private State state = State.NOT_READY;
private T next;
/**
* Constructor for use by subclasses.
*/
protected AbstractIterator() {
}
private enum State {
/**
* We have computed the next element and haven't returned it yet.
*/
READY,
/**
* We haven't yet computed or have already returned the element.
*/
NOT_READY,
/**
* We have reached the end of the data and are finished.
*/
DONE,
/**
* We've suffered an exception and are kaput.
*/
FAILED,
}
/**
* Returns the next element. <b>Note:</b> the implementation must call {@link
* #endOfData()} when there are no elements left in the iteration. Failure to
* do so could result in an infinite loop.
*
* <p>The initial invocation of {@link #hasNext()} or {@link #next()} calls
* this method, as does the first invocation of {@code hasNext} or {@code
* next} following each successful call to {@code next}. Once the
* implementation either invokes {@code endOfData} or throws an exception,
* {@code computeNext} is guaranteed to never be called again.
*
* <p>If this method throws an exception, it will propagate outward to the
* {@code hasNext} or {@code next} invocation that invoked this method. Any
* further attempts to use the iterator will result in an {@link
* IllegalStateException}.
*
* <p>The implementation of this method may not invoke the {@code hasNext},
* {@code next}, or {@link #peek()} methods on this instance; if it does, an
* {@code IllegalStateException} will result.
*
* @return the next element if there was one. If {@code endOfData} was called
* during execution, the return value will be ignored.
* @throws RuntimeException if any unrecoverable error happens. This exception
* will propagate outward to the {@code hasNext()}, {@code next()}, or
* {@code peek()} invocation that invoked this method. Any further
* attempts to use the iterator will result in an
* {@link IllegalStateException}.
*/
protected abstract T computeNext();
/**
* Implementations of {@link #computeNext} <b>must</b> invoke this method when
* there are no elements left in the iteration.
*
* @return {@code null}; a convenience so your {@code computeNext}
* implementation can use the simple statement {@code return endOfData();}
*/
protected final T endOfData() {
state = State.DONE;
return null;
}
@Override
public final boolean hasNext() { | // Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static void checkState(boolean expression) {
// if (!expression) {
// throw new IllegalStateException();
// }
// }
// Path: src/main/java/com/fernandocejas/arrow/collections/AbstractIterator.java
import java.util.NoSuchElementException;
import static com.fernandocejas.arrow.checks.Preconditions.checkState;
/**
* Copyright (C) 2007 The Guava Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.fernandocejas.arrow.collections;
/**
* This class provides a skeletal implementation of the {@code Iterator}
* interface, to make this interface easier to implement for certain types of
* data sources.
*
* <p>{@code Iterator} requires its implementations to support querying the
* end-of-data status without changing the iterator's state, using the {@link
* #hasNext} method. But many data sources, such as {@link
* java.io.Reader#read()}, do not expose this information; the only way to
* discover whether there is any data left is by trying to retrieve it. These
* types of data sources are ordinarily difficult to write iterators for. But
* using this class, one must implement only the {@link #computeNext} method,
* and invoke the {@link #endOfData} method when appropriate.
*
* <p>Another example is an iterator that skips over null elements in a backing
* iterator. This could be implemented as: <pre> {@code
*
* public static Iterator<String> skipNulls(final Iterator<String> in) {
* return new AbstractIterator<String>() {
* protected String computeNext() {
* while (in.hasNext()) {
* String s = in.next();
* if (s != null) {
* return s;
* }
* }
* return endOfData();
* }
* };
* }}</pre>
*
* <p>This class supports iterators that include null elements.
*
* @author Kevin Bourrillion
* @since 2.0 (imported from Google Collections Library)
*
* <p><b>This class contains code derived from <a href="https://github.com/google/guava">Google
* Guava</a></b>
*/
public abstract class AbstractIterator<T> extends UnmodifiableIterator<T> {
private State state = State.NOT_READY;
private T next;
/**
* Constructor for use by subclasses.
*/
protected AbstractIterator() {
}
private enum State {
/**
* We have computed the next element and haven't returned it yet.
*/
READY,
/**
* We haven't yet computed or have already returned the element.
*/
NOT_READY,
/**
* We have reached the end of the data and are finished.
*/
DONE,
/**
* We've suffered an exception and are kaput.
*/
FAILED,
}
/**
* Returns the next element. <b>Note:</b> the implementation must call {@link
* #endOfData()} when there are no elements left in the iteration. Failure to
* do so could result in an infinite loop.
*
* <p>The initial invocation of {@link #hasNext()} or {@link #next()} calls
* this method, as does the first invocation of {@code hasNext} or {@code
* next} following each successful call to {@code next}. Once the
* implementation either invokes {@code endOfData} or throws an exception,
* {@code computeNext} is guaranteed to never be called again.
*
* <p>If this method throws an exception, it will propagate outward to the
* {@code hasNext} or {@code next} invocation that invoked this method. Any
* further attempts to use the iterator will result in an {@link
* IllegalStateException}.
*
* <p>The implementation of this method may not invoke the {@code hasNext},
* {@code next}, or {@link #peek()} methods on this instance; if it does, an
* {@code IllegalStateException} will result.
*
* @return the next element if there was one. If {@code endOfData} was called
* during execution, the return value will be ignored.
* @throws RuntimeException if any unrecoverable error happens. This exception
* will propagate outward to the {@code hasNext()}, {@code next()}, or
* {@code peek()} invocation that invoked this method. Any further
* attempts to use the iterator will result in an
* {@link IllegalStateException}.
*/
protected abstract T computeNext();
/**
* Implementations of {@link #computeNext} <b>must</b> invoke this method when
* there are no elements left in the iteration.
*
* @return {@code null}; a convenience so your {@code computeNext}
* implementation can use the simple statement {@code return endOfData();}
*/
protected final T endOfData() {
state = State.DONE;
return null;
}
@Override
public final boolean hasNext() { | checkState(state != State.FAILED); |
android10/arrow | src/main/java/com/fernandocejas/arrow/strings/Joiner.java | // Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static <T> T checkNotNull(T reference) {
// if (reference == null) {
// throw new NullPointerException();
// }
// return reference;
// }
| import java.io.IOException;
import java.util.AbstractList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.Map;
import org.jetbrains.annotations.Nullable;
import static com.fernandocejas.arrow.checks.Preconditions.checkNotNull; | /**
* Copyright (C) 2008 The Guava Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.fernandocejas.arrow.strings;
/**
* An object which joins pieces of text (specified as an array, {@link Iterable}, varargs or even a
* {@link Map}) with a separator. It either appends the results to an {@link Appendable} or returns
* them as a {@link String}. Example: <pre> {@code
* <p/>
* Joiner joiner = Joiner.on("; ").skipNulls();
* . . .
* return joiner.join("Harry", null, "Ron", "Hermione");}</pre>
* <p/>
* <p>This returns the string {@code "Harry; Ron; Hermione"}. Note that all input elements are
* converted to strings using {@link Object#toString()} before being appended.
* <p/>
* <p>If neither {@link #skipNulls()} nor {@link #useForNull(String)} is specified, the joining
* methods will throw {@link NullPointerException} if any given element is null.
* <p/>
* <p><b>Warning: joiner instances are always immutable</b>; a configuration method such as {@code
* useForNull} has no effect on the instance it is invoked on! You must store and use the new
* joiner
* instance returned by the method. This makes joiners thread-safe, and safe to store as {@code
* static final} constants. <pre> {@code
* <p/>
* // Bad! Do not do this!
* Joiner joiner = Joiner.on(',');
* joiner.skipNulls(); // does nothing!
* return joiner.join("wrong", null, "wrong");}</pre>
* <p/>
* <p>See the Guava User Guide article on <a href=
* "http://code.google.com/p/guava-libraries/wiki/StringsExplained#Joiner">{@code Joiner}</a>.
*
* <p><b>This class contains code derived from <a href="https://github.com/google/guava">Google
* Guava</a></b>
*
* @author Kevin Bourrillion
*/
public class Joiner {
private final String separator;
Joiner(String separator) { | // Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static <T> T checkNotNull(T reference) {
// if (reference == null) {
// throw new NullPointerException();
// }
// return reference;
// }
// Path: src/main/java/com/fernandocejas/arrow/strings/Joiner.java
import java.io.IOException;
import java.util.AbstractList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.Map;
import org.jetbrains.annotations.Nullable;
import static com.fernandocejas.arrow.checks.Preconditions.checkNotNull;
/**
* Copyright (C) 2008 The Guava Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.fernandocejas.arrow.strings;
/**
* An object which joins pieces of text (specified as an array, {@link Iterable}, varargs or even a
* {@link Map}) with a separator. It either appends the results to an {@link Appendable} or returns
* them as a {@link String}. Example: <pre> {@code
* <p/>
* Joiner joiner = Joiner.on("; ").skipNulls();
* . . .
* return joiner.join("Harry", null, "Ron", "Hermione");}</pre>
* <p/>
* <p>This returns the string {@code "Harry; Ron; Hermione"}. Note that all input elements are
* converted to strings using {@link Object#toString()} before being appended.
* <p/>
* <p>If neither {@link #skipNulls()} nor {@link #useForNull(String)} is specified, the joining
* methods will throw {@link NullPointerException} if any given element is null.
* <p/>
* <p><b>Warning: joiner instances are always immutable</b>; a configuration method such as {@code
* useForNull} has no effect on the instance it is invoked on! You must store and use the new
* joiner
* instance returned by the method. This makes joiners thread-safe, and safe to store as {@code
* static final} constants. <pre> {@code
* <p/>
* // Bad! Do not do this!
* Joiner joiner = Joiner.on(',');
* joiner.skipNulls(); // does nothing!
* return joiner.join("wrong", null, "wrong");}</pre>
* <p/>
* <p>See the Guava User Guide article on <a href=
* "http://code.google.com/p/guava-libraries/wiki/StringsExplained#Joiner">{@code Joiner}</a>.
*
* <p><b>This class contains code derived from <a href="https://github.com/google/guava">Google
* Guava</a></b>
*
* @author Kevin Bourrillion
*/
public class Joiner {
private final String separator;
Joiner(String separator) { | this.separator = checkNotNull(separator); |
android10/arrow | src/main/java/com/fernandocejas/arrow/optional/Absent.java | // Path: src/main/java/com/fernandocejas/arrow/functions/Function.java
// public interface Function<F, T> {
// /**
// * Returns the result of applying this function to {@code input}. This method is <i>generally
// * expected</i>, but not absolutely required, to have the following properties:
// *
// * <ul>
// * <li>Its execution does not cause any observable side effects.
// * <li>The computation is <i>consistent with equals</i>.
// * Objects.equal}{@code (a, b)} implies that {@code Objects.equal(function.apply(a),
// * function.apply(b))}.
// * </ul>
// *
// * @throws NullPointerException if {@code input} is null
// */
// @Nullable T apply(F input);
//
// /**
// * Indicates whether another object is equal to this function.
// *
// * <p>Most implementations will have no reason to override the behavior of {@link Object#equals}.
// * However, an implementation may also choose to return {@code true} whenever {@code object} is a
// * {@link Function} that it considers <i>interchangeable</i> with this one. "Interchangeable"
// * <i>typically</i> means that {@code Objects.equal(this.apply(f), that.apply(f))} is true for
// * all
// * {@code f} of type {@code F}. Note that a {@code false} result from this method does not imply
// * that the functions are known <i>not</i> to be interchangeable.
// */
// @Override boolean equals(@Nullable Object object);
// }
//
// Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static <T> T checkNotNull(T reference) {
// if (reference == null) {
// throw new NullPointerException();
// }
// return reference;
// }
| import com.fernandocejas.arrow.functions.Function;
import java.util.Collections;
import java.util.Set;
import org.jetbrains.annotations.Nullable;
import static com.fernandocejas.arrow.checks.Preconditions.checkNotNull; | /**
* Copyright (C) 2011 The Guava Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.fernandocejas.arrow.optional;
/**
* Implementation of an {@link Optional} not containing a reference.
*
* <p><b>This class contains code derived from <a href="https://github.com/google/guava">Google
* Guava</a></b>
*/
final class Absent<T> extends Optional<T> {
private static final long serialVersionUID = 0;
static final Absent<Object> INSTANCE = new Absent<>();
@SuppressWarnings("unchecked") // implementation is "fully variant"
static <T> Optional<T> withType() {
return (Optional<T>) INSTANCE;
}
private Absent() {
}
@Override
public boolean isPresent() {
return false;
}
@Override
public T get() {
throw new IllegalStateException("Optional.get() cannot be called on an absent value");
}
@Override
public T or(T defaultValue) { | // Path: src/main/java/com/fernandocejas/arrow/functions/Function.java
// public interface Function<F, T> {
// /**
// * Returns the result of applying this function to {@code input}. This method is <i>generally
// * expected</i>, but not absolutely required, to have the following properties:
// *
// * <ul>
// * <li>Its execution does not cause any observable side effects.
// * <li>The computation is <i>consistent with equals</i>.
// * Objects.equal}{@code (a, b)} implies that {@code Objects.equal(function.apply(a),
// * function.apply(b))}.
// * </ul>
// *
// * @throws NullPointerException if {@code input} is null
// */
// @Nullable T apply(F input);
//
// /**
// * Indicates whether another object is equal to this function.
// *
// * <p>Most implementations will have no reason to override the behavior of {@link Object#equals}.
// * However, an implementation may also choose to return {@code true} whenever {@code object} is a
// * {@link Function} that it considers <i>interchangeable</i> with this one. "Interchangeable"
// * <i>typically</i> means that {@code Objects.equal(this.apply(f), that.apply(f))} is true for
// * all
// * {@code f} of type {@code F}. Note that a {@code false} result from this method does not imply
// * that the functions are known <i>not</i> to be interchangeable.
// */
// @Override boolean equals(@Nullable Object object);
// }
//
// Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static <T> T checkNotNull(T reference) {
// if (reference == null) {
// throw new NullPointerException();
// }
// return reference;
// }
// Path: src/main/java/com/fernandocejas/arrow/optional/Absent.java
import com.fernandocejas.arrow.functions.Function;
import java.util.Collections;
import java.util.Set;
import org.jetbrains.annotations.Nullable;
import static com.fernandocejas.arrow.checks.Preconditions.checkNotNull;
/**
* Copyright (C) 2011 The Guava Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.fernandocejas.arrow.optional;
/**
* Implementation of an {@link Optional} not containing a reference.
*
* <p><b>This class contains code derived from <a href="https://github.com/google/guava">Google
* Guava</a></b>
*/
final class Absent<T> extends Optional<T> {
private static final long serialVersionUID = 0;
static final Absent<Object> INSTANCE = new Absent<>();
@SuppressWarnings("unchecked") // implementation is "fully variant"
static <T> Optional<T> withType() {
return (Optional<T>) INSTANCE;
}
private Absent() {
}
@Override
public boolean isPresent() {
return false;
}
@Override
public T get() {
throw new IllegalStateException("Optional.get() cannot be called on an absent value");
}
@Override
public T or(T defaultValue) { | return checkNotNull(defaultValue, "use Optional.orNull() instead of Optional.or(null)"); |
android10/arrow | src/main/java/com/fernandocejas/arrow/optional/Absent.java | // Path: src/main/java/com/fernandocejas/arrow/functions/Function.java
// public interface Function<F, T> {
// /**
// * Returns the result of applying this function to {@code input}. This method is <i>generally
// * expected</i>, but not absolutely required, to have the following properties:
// *
// * <ul>
// * <li>Its execution does not cause any observable side effects.
// * <li>The computation is <i>consistent with equals</i>.
// * Objects.equal}{@code (a, b)} implies that {@code Objects.equal(function.apply(a),
// * function.apply(b))}.
// * </ul>
// *
// * @throws NullPointerException if {@code input} is null
// */
// @Nullable T apply(F input);
//
// /**
// * Indicates whether another object is equal to this function.
// *
// * <p>Most implementations will have no reason to override the behavior of {@link Object#equals}.
// * However, an implementation may also choose to return {@code true} whenever {@code object} is a
// * {@link Function} that it considers <i>interchangeable</i> with this one. "Interchangeable"
// * <i>typically</i> means that {@code Objects.equal(this.apply(f), that.apply(f))} is true for
// * all
// * {@code f} of type {@code F}. Note that a {@code false} result from this method does not imply
// * that the functions are known <i>not</i> to be interchangeable.
// */
// @Override boolean equals(@Nullable Object object);
// }
//
// Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static <T> T checkNotNull(T reference) {
// if (reference == null) {
// throw new NullPointerException();
// }
// return reference;
// }
| import com.fernandocejas.arrow.functions.Function;
import java.util.Collections;
import java.util.Set;
import org.jetbrains.annotations.Nullable;
import static com.fernandocejas.arrow.checks.Preconditions.checkNotNull; | }
@Override
public T get() {
throw new IllegalStateException("Optional.get() cannot be called on an absent value");
}
@Override
public T or(T defaultValue) {
return checkNotNull(defaultValue, "use Optional.orNull() instead of Optional.or(null)");
}
@SuppressWarnings("unchecked") // safe covariant cast
@Override
public Optional<T> or(Optional<? extends T> secondChoice) {
return (Optional<T>) checkNotNull(secondChoice);
}
@Override
@Nullable
public T orNull() {
return null;
}
@Override
public Set<T> asSet() {
return Collections.emptySet();
}
@Override | // Path: src/main/java/com/fernandocejas/arrow/functions/Function.java
// public interface Function<F, T> {
// /**
// * Returns the result of applying this function to {@code input}. This method is <i>generally
// * expected</i>, but not absolutely required, to have the following properties:
// *
// * <ul>
// * <li>Its execution does not cause any observable side effects.
// * <li>The computation is <i>consistent with equals</i>.
// * Objects.equal}{@code (a, b)} implies that {@code Objects.equal(function.apply(a),
// * function.apply(b))}.
// * </ul>
// *
// * @throws NullPointerException if {@code input} is null
// */
// @Nullable T apply(F input);
//
// /**
// * Indicates whether another object is equal to this function.
// *
// * <p>Most implementations will have no reason to override the behavior of {@link Object#equals}.
// * However, an implementation may also choose to return {@code true} whenever {@code object} is a
// * {@link Function} that it considers <i>interchangeable</i> with this one. "Interchangeable"
// * <i>typically</i> means that {@code Objects.equal(this.apply(f), that.apply(f))} is true for
// * all
// * {@code f} of type {@code F}. Note that a {@code false} result from this method does not imply
// * that the functions are known <i>not</i> to be interchangeable.
// */
// @Override boolean equals(@Nullable Object object);
// }
//
// Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static <T> T checkNotNull(T reference) {
// if (reference == null) {
// throw new NullPointerException();
// }
// return reference;
// }
// Path: src/main/java/com/fernandocejas/arrow/optional/Absent.java
import com.fernandocejas.arrow.functions.Function;
import java.util.Collections;
import java.util.Set;
import org.jetbrains.annotations.Nullable;
import static com.fernandocejas.arrow.checks.Preconditions.checkNotNull;
}
@Override
public T get() {
throw new IllegalStateException("Optional.get() cannot be called on an absent value");
}
@Override
public T or(T defaultValue) {
return checkNotNull(defaultValue, "use Optional.orNull() instead of Optional.or(null)");
}
@SuppressWarnings("unchecked") // safe covariant cast
@Override
public Optional<T> or(Optional<? extends T> secondChoice) {
return (Optional<T>) checkNotNull(secondChoice);
}
@Override
@Nullable
public T orNull() {
return null;
}
@Override
public Set<T> asSet() {
return Collections.emptySet();
}
@Override | public <V> Optional<V> transform(Function<? super T, V> function) { |
android10/arrow | src/main/java/com/fernandocejas/arrow/optional/Present.java | // Path: src/main/java/com/fernandocejas/arrow/functions/Function.java
// public interface Function<F, T> {
// /**
// * Returns the result of applying this function to {@code input}. This method is <i>generally
// * expected</i>, but not absolutely required, to have the following properties:
// *
// * <ul>
// * <li>Its execution does not cause any observable side effects.
// * <li>The computation is <i>consistent with equals</i>.
// * Objects.equal}{@code (a, b)} implies that {@code Objects.equal(function.apply(a),
// * function.apply(b))}.
// * </ul>
// *
// * @throws NullPointerException if {@code input} is null
// */
// @Nullable T apply(F input);
//
// /**
// * Indicates whether another object is equal to this function.
// *
// * <p>Most implementations will have no reason to override the behavior of {@link Object#equals}.
// * However, an implementation may also choose to return {@code true} whenever {@code object} is a
// * {@link Function} that it considers <i>interchangeable</i> with this one. "Interchangeable"
// * <i>typically</i> means that {@code Objects.equal(this.apply(f), that.apply(f))} is true for
// * all
// * {@code f} of type {@code F}. Note that a {@code false} result from this method does not imply
// * that the functions are known <i>not</i> to be interchangeable.
// */
// @Override boolean equals(@Nullable Object object);
// }
//
// Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static <T> T checkNotNull(T reference) {
// if (reference == null) {
// throw new NullPointerException();
// }
// return reference;
// }
| import com.fernandocejas.arrow.functions.Function;
import java.util.Collections;
import java.util.Set;
import org.jetbrains.annotations.Nullable;
import static com.fernandocejas.arrow.checks.Preconditions.checkNotNull; | /**
* Copyright (C) 2011 The Guava Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.fernandocejas.arrow.optional;
/**
* Implementation of an {@link Optional} containing a reference.
*
* <p><b>This class contains code derived from <a href="https://github.com/google/guava">Google
* Guava</a></b>
*/
final class Present<T> extends Optional<T> {
private static final long serialVersionUID = 0;
private final T reference;
Present(T reference) {
this.reference = reference;
}
@Override
public boolean isPresent() {
return true;
}
@Override
public T get() {
return reference;
}
@Override
public T or(T defaultValue) { | // Path: src/main/java/com/fernandocejas/arrow/functions/Function.java
// public interface Function<F, T> {
// /**
// * Returns the result of applying this function to {@code input}. This method is <i>generally
// * expected</i>, but not absolutely required, to have the following properties:
// *
// * <ul>
// * <li>Its execution does not cause any observable side effects.
// * <li>The computation is <i>consistent with equals</i>.
// * Objects.equal}{@code (a, b)} implies that {@code Objects.equal(function.apply(a),
// * function.apply(b))}.
// * </ul>
// *
// * @throws NullPointerException if {@code input} is null
// */
// @Nullable T apply(F input);
//
// /**
// * Indicates whether another object is equal to this function.
// *
// * <p>Most implementations will have no reason to override the behavior of {@link Object#equals}.
// * However, an implementation may also choose to return {@code true} whenever {@code object} is a
// * {@link Function} that it considers <i>interchangeable</i> with this one. "Interchangeable"
// * <i>typically</i> means that {@code Objects.equal(this.apply(f), that.apply(f))} is true for
// * all
// * {@code f} of type {@code F}. Note that a {@code false} result from this method does not imply
// * that the functions are known <i>not</i> to be interchangeable.
// */
// @Override boolean equals(@Nullable Object object);
// }
//
// Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static <T> T checkNotNull(T reference) {
// if (reference == null) {
// throw new NullPointerException();
// }
// return reference;
// }
// Path: src/main/java/com/fernandocejas/arrow/optional/Present.java
import com.fernandocejas.arrow.functions.Function;
import java.util.Collections;
import java.util.Set;
import org.jetbrains.annotations.Nullable;
import static com.fernandocejas.arrow.checks.Preconditions.checkNotNull;
/**
* Copyright (C) 2011 The Guava Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.fernandocejas.arrow.optional;
/**
* Implementation of an {@link Optional} containing a reference.
*
* <p><b>This class contains code derived from <a href="https://github.com/google/guava">Google
* Guava</a></b>
*/
final class Present<T> extends Optional<T> {
private static final long serialVersionUID = 0;
private final T reference;
Present(T reference) {
this.reference = reference;
}
@Override
public boolean isPresent() {
return true;
}
@Override
public T get() {
return reference;
}
@Override
public T or(T defaultValue) { | checkNotNull(defaultValue, "use Optional.orNull() instead of Optional.or(null)"); |
android10/arrow | src/main/java/com/fernandocejas/arrow/optional/Present.java | // Path: src/main/java/com/fernandocejas/arrow/functions/Function.java
// public interface Function<F, T> {
// /**
// * Returns the result of applying this function to {@code input}. This method is <i>generally
// * expected</i>, but not absolutely required, to have the following properties:
// *
// * <ul>
// * <li>Its execution does not cause any observable side effects.
// * <li>The computation is <i>consistent with equals</i>.
// * Objects.equal}{@code (a, b)} implies that {@code Objects.equal(function.apply(a),
// * function.apply(b))}.
// * </ul>
// *
// * @throws NullPointerException if {@code input} is null
// */
// @Nullable T apply(F input);
//
// /**
// * Indicates whether another object is equal to this function.
// *
// * <p>Most implementations will have no reason to override the behavior of {@link Object#equals}.
// * However, an implementation may also choose to return {@code true} whenever {@code object} is a
// * {@link Function} that it considers <i>interchangeable</i> with this one. "Interchangeable"
// * <i>typically</i> means that {@code Objects.equal(this.apply(f), that.apply(f))} is true for
// * all
// * {@code f} of type {@code F}. Note that a {@code false} result from this method does not imply
// * that the functions are known <i>not</i> to be interchangeable.
// */
// @Override boolean equals(@Nullable Object object);
// }
//
// Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static <T> T checkNotNull(T reference) {
// if (reference == null) {
// throw new NullPointerException();
// }
// return reference;
// }
| import com.fernandocejas.arrow.functions.Function;
import java.util.Collections;
import java.util.Set;
import org.jetbrains.annotations.Nullable;
import static com.fernandocejas.arrow.checks.Preconditions.checkNotNull; | }
@Override
public T get() {
return reference;
}
@Override
public T or(T defaultValue) {
checkNotNull(defaultValue, "use Optional.orNull() instead of Optional.or(null)");
return reference;
}
@Override
public Optional<T> or(Optional<? extends T> secondChoice) {
checkNotNull(secondChoice);
return this;
}
@Override
public T orNull() {
return reference;
}
@Override
public Set<T> asSet() {
return Collections.singleton(reference);
}
@Override | // Path: src/main/java/com/fernandocejas/arrow/functions/Function.java
// public interface Function<F, T> {
// /**
// * Returns the result of applying this function to {@code input}. This method is <i>generally
// * expected</i>, but not absolutely required, to have the following properties:
// *
// * <ul>
// * <li>Its execution does not cause any observable side effects.
// * <li>The computation is <i>consistent with equals</i>.
// * Objects.equal}{@code (a, b)} implies that {@code Objects.equal(function.apply(a),
// * function.apply(b))}.
// * </ul>
// *
// * @throws NullPointerException if {@code input} is null
// */
// @Nullable T apply(F input);
//
// /**
// * Indicates whether another object is equal to this function.
// *
// * <p>Most implementations will have no reason to override the behavior of {@link Object#equals}.
// * However, an implementation may also choose to return {@code true} whenever {@code object} is a
// * {@link Function} that it considers <i>interchangeable</i> with this one. "Interchangeable"
// * <i>typically</i> means that {@code Objects.equal(this.apply(f), that.apply(f))} is true for
// * all
// * {@code f} of type {@code F}. Note that a {@code false} result from this method does not imply
// * that the functions are known <i>not</i> to be interchangeable.
// */
// @Override boolean equals(@Nullable Object object);
// }
//
// Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static <T> T checkNotNull(T reference) {
// if (reference == null) {
// throw new NullPointerException();
// }
// return reference;
// }
// Path: src/main/java/com/fernandocejas/arrow/optional/Present.java
import com.fernandocejas.arrow.functions.Function;
import java.util.Collections;
import java.util.Set;
import org.jetbrains.annotations.Nullable;
import static com.fernandocejas.arrow.checks.Preconditions.checkNotNull;
}
@Override
public T get() {
return reference;
}
@Override
public T or(T defaultValue) {
checkNotNull(defaultValue, "use Optional.orNull() instead of Optional.or(null)");
return reference;
}
@Override
public Optional<T> or(Optional<? extends T> secondChoice) {
checkNotNull(secondChoice);
return this;
}
@Override
public T orNull() {
return reference;
}
@Override
public Set<T> asSet() {
return Collections.singleton(reference);
}
@Override | public <V> Optional<V> transform(Function<? super T, V> function) { |
android10/arrow | src/main/java/com/fernandocejas/arrow/collections/ReverseList.java | // Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static int checkElementIndex(int index, int size) {
// return checkElementIndex(index, size, "index");
// }
//
// Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static <T> T checkNotNull(T reference) {
// if (reference == null) {
// throw new NullPointerException();
// }
// return reference;
// }
//
// Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static int checkPositionIndex(int index, int size) {
// return checkPositionIndex(index, size, "index");
// }
//
// Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static void checkPositionIndexes(int start, int end, int size) {
// // Carefully optimized for execution by hotspot (explanatory comment above)
// if (start < 0 || end < start || end > size) {
// throw new IndexOutOfBoundsException(badPositionIndexes(start, end, size));
// }
// }
//
// Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static void checkState(boolean expression) {
// if (!expression) {
// throw new IllegalStateException();
// }
// }
| import java.util.AbstractList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.NoSuchElementException;
import org.jetbrains.annotations.Nullable;
import static com.fernandocejas.arrow.checks.Preconditions.checkElementIndex;
import static com.fernandocejas.arrow.checks.Preconditions.checkNotNull;
import static com.fernandocejas.arrow.checks.Preconditions.checkPositionIndex;
import static com.fernandocejas.arrow.checks.Preconditions.checkPositionIndexes;
import static com.fernandocejas.arrow.checks.Preconditions.checkState; | /**
* Copyright (C) 2007 The Guava Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.fernandocejas.arrow.collections;
class ReverseList<T> extends AbstractList<T> {
private final List<T> forwardList;
ReverseList(List<T> forwardList) { | // Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static int checkElementIndex(int index, int size) {
// return checkElementIndex(index, size, "index");
// }
//
// Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static <T> T checkNotNull(T reference) {
// if (reference == null) {
// throw new NullPointerException();
// }
// return reference;
// }
//
// Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static int checkPositionIndex(int index, int size) {
// return checkPositionIndex(index, size, "index");
// }
//
// Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static void checkPositionIndexes(int start, int end, int size) {
// // Carefully optimized for execution by hotspot (explanatory comment above)
// if (start < 0 || end < start || end > size) {
// throw new IndexOutOfBoundsException(badPositionIndexes(start, end, size));
// }
// }
//
// Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static void checkState(boolean expression) {
// if (!expression) {
// throw new IllegalStateException();
// }
// }
// Path: src/main/java/com/fernandocejas/arrow/collections/ReverseList.java
import java.util.AbstractList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.NoSuchElementException;
import org.jetbrains.annotations.Nullable;
import static com.fernandocejas.arrow.checks.Preconditions.checkElementIndex;
import static com.fernandocejas.arrow.checks.Preconditions.checkNotNull;
import static com.fernandocejas.arrow.checks.Preconditions.checkPositionIndex;
import static com.fernandocejas.arrow.checks.Preconditions.checkPositionIndexes;
import static com.fernandocejas.arrow.checks.Preconditions.checkState;
/**
* Copyright (C) 2007 The Guava Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.fernandocejas.arrow.collections;
class ReverseList<T> extends AbstractList<T> {
private final List<T> forwardList;
ReverseList(List<T> forwardList) { | this.forwardList = checkNotNull(forwardList); |
android10/arrow | src/main/java/com/fernandocejas/arrow/collections/ReverseList.java | // Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static int checkElementIndex(int index, int size) {
// return checkElementIndex(index, size, "index");
// }
//
// Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static <T> T checkNotNull(T reference) {
// if (reference == null) {
// throw new NullPointerException();
// }
// return reference;
// }
//
// Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static int checkPositionIndex(int index, int size) {
// return checkPositionIndex(index, size, "index");
// }
//
// Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static void checkPositionIndexes(int start, int end, int size) {
// // Carefully optimized for execution by hotspot (explanatory comment above)
// if (start < 0 || end < start || end > size) {
// throw new IndexOutOfBoundsException(badPositionIndexes(start, end, size));
// }
// }
//
// Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static void checkState(boolean expression) {
// if (!expression) {
// throw new IllegalStateException();
// }
// }
| import java.util.AbstractList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.NoSuchElementException;
import org.jetbrains.annotations.Nullable;
import static com.fernandocejas.arrow.checks.Preconditions.checkElementIndex;
import static com.fernandocejas.arrow.checks.Preconditions.checkNotNull;
import static com.fernandocejas.arrow.checks.Preconditions.checkPositionIndex;
import static com.fernandocejas.arrow.checks.Preconditions.checkPositionIndexes;
import static com.fernandocejas.arrow.checks.Preconditions.checkState; | /**
* Copyright (C) 2007 The Guava Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.fernandocejas.arrow.collections;
class ReverseList<T> extends AbstractList<T> {
private final List<T> forwardList;
ReverseList(List<T> forwardList) {
this.forwardList = checkNotNull(forwardList);
}
List<T> getForwardList() {
return forwardList;
}
private int reverseIndex(int index) {
int size = size(); | // Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static int checkElementIndex(int index, int size) {
// return checkElementIndex(index, size, "index");
// }
//
// Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static <T> T checkNotNull(T reference) {
// if (reference == null) {
// throw new NullPointerException();
// }
// return reference;
// }
//
// Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static int checkPositionIndex(int index, int size) {
// return checkPositionIndex(index, size, "index");
// }
//
// Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static void checkPositionIndexes(int start, int end, int size) {
// // Carefully optimized for execution by hotspot (explanatory comment above)
// if (start < 0 || end < start || end > size) {
// throw new IndexOutOfBoundsException(badPositionIndexes(start, end, size));
// }
// }
//
// Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static void checkState(boolean expression) {
// if (!expression) {
// throw new IllegalStateException();
// }
// }
// Path: src/main/java/com/fernandocejas/arrow/collections/ReverseList.java
import java.util.AbstractList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.NoSuchElementException;
import org.jetbrains.annotations.Nullable;
import static com.fernandocejas.arrow.checks.Preconditions.checkElementIndex;
import static com.fernandocejas.arrow.checks.Preconditions.checkNotNull;
import static com.fernandocejas.arrow.checks.Preconditions.checkPositionIndex;
import static com.fernandocejas.arrow.checks.Preconditions.checkPositionIndexes;
import static com.fernandocejas.arrow.checks.Preconditions.checkState;
/**
* Copyright (C) 2007 The Guava Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.fernandocejas.arrow.collections;
class ReverseList<T> extends AbstractList<T> {
private final List<T> forwardList;
ReverseList(List<T> forwardList) {
this.forwardList = checkNotNull(forwardList);
}
List<T> getForwardList() {
return forwardList;
}
private int reverseIndex(int index) {
int size = size(); | checkElementIndex(index, size); |
android10/arrow | src/main/java/com/fernandocejas/arrow/collections/ReverseList.java | // Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static int checkElementIndex(int index, int size) {
// return checkElementIndex(index, size, "index");
// }
//
// Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static <T> T checkNotNull(T reference) {
// if (reference == null) {
// throw new NullPointerException();
// }
// return reference;
// }
//
// Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static int checkPositionIndex(int index, int size) {
// return checkPositionIndex(index, size, "index");
// }
//
// Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static void checkPositionIndexes(int start, int end, int size) {
// // Carefully optimized for execution by hotspot (explanatory comment above)
// if (start < 0 || end < start || end > size) {
// throw new IndexOutOfBoundsException(badPositionIndexes(start, end, size));
// }
// }
//
// Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static void checkState(boolean expression) {
// if (!expression) {
// throw new IllegalStateException();
// }
// }
| import java.util.AbstractList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.NoSuchElementException;
import org.jetbrains.annotations.Nullable;
import static com.fernandocejas.arrow.checks.Preconditions.checkElementIndex;
import static com.fernandocejas.arrow.checks.Preconditions.checkNotNull;
import static com.fernandocejas.arrow.checks.Preconditions.checkPositionIndex;
import static com.fernandocejas.arrow.checks.Preconditions.checkPositionIndexes;
import static com.fernandocejas.arrow.checks.Preconditions.checkState; | /**
* Copyright (C) 2007 The Guava Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.fernandocejas.arrow.collections;
class ReverseList<T> extends AbstractList<T> {
private final List<T> forwardList;
ReverseList(List<T> forwardList) {
this.forwardList = checkNotNull(forwardList);
}
List<T> getForwardList() {
return forwardList;
}
private int reverseIndex(int index) {
int size = size();
checkElementIndex(index, size);
return size - 1 - index;
}
private int reversePosition(int index) {
int size = size(); | // Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static int checkElementIndex(int index, int size) {
// return checkElementIndex(index, size, "index");
// }
//
// Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static <T> T checkNotNull(T reference) {
// if (reference == null) {
// throw new NullPointerException();
// }
// return reference;
// }
//
// Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static int checkPositionIndex(int index, int size) {
// return checkPositionIndex(index, size, "index");
// }
//
// Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static void checkPositionIndexes(int start, int end, int size) {
// // Carefully optimized for execution by hotspot (explanatory comment above)
// if (start < 0 || end < start || end > size) {
// throw new IndexOutOfBoundsException(badPositionIndexes(start, end, size));
// }
// }
//
// Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static void checkState(boolean expression) {
// if (!expression) {
// throw new IllegalStateException();
// }
// }
// Path: src/main/java/com/fernandocejas/arrow/collections/ReverseList.java
import java.util.AbstractList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.NoSuchElementException;
import org.jetbrains.annotations.Nullable;
import static com.fernandocejas.arrow.checks.Preconditions.checkElementIndex;
import static com.fernandocejas.arrow.checks.Preconditions.checkNotNull;
import static com.fernandocejas.arrow.checks.Preconditions.checkPositionIndex;
import static com.fernandocejas.arrow.checks.Preconditions.checkPositionIndexes;
import static com.fernandocejas.arrow.checks.Preconditions.checkState;
/**
* Copyright (C) 2007 The Guava Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.fernandocejas.arrow.collections;
class ReverseList<T> extends AbstractList<T> {
private final List<T> forwardList;
ReverseList(List<T> forwardList) {
this.forwardList = checkNotNull(forwardList);
}
List<T> getForwardList() {
return forwardList;
}
private int reverseIndex(int index) {
int size = size();
checkElementIndex(index, size);
return size - 1 - index;
}
private int reversePosition(int index) {
int size = size(); | checkPositionIndex(index, size); |
android10/arrow | src/main/java/com/fernandocejas/arrow/collections/ReverseList.java | // Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static int checkElementIndex(int index, int size) {
// return checkElementIndex(index, size, "index");
// }
//
// Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static <T> T checkNotNull(T reference) {
// if (reference == null) {
// throw new NullPointerException();
// }
// return reference;
// }
//
// Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static int checkPositionIndex(int index, int size) {
// return checkPositionIndex(index, size, "index");
// }
//
// Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static void checkPositionIndexes(int start, int end, int size) {
// // Carefully optimized for execution by hotspot (explanatory comment above)
// if (start < 0 || end < start || end > size) {
// throw new IndexOutOfBoundsException(badPositionIndexes(start, end, size));
// }
// }
//
// Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static void checkState(boolean expression) {
// if (!expression) {
// throw new IllegalStateException();
// }
// }
| import java.util.AbstractList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.NoSuchElementException;
import org.jetbrains.annotations.Nullable;
import static com.fernandocejas.arrow.checks.Preconditions.checkElementIndex;
import static com.fernandocejas.arrow.checks.Preconditions.checkNotNull;
import static com.fernandocejas.arrow.checks.Preconditions.checkPositionIndex;
import static com.fernandocejas.arrow.checks.Preconditions.checkPositionIndexes;
import static com.fernandocejas.arrow.checks.Preconditions.checkState; | forwardList.clear();
}
@Override
public T remove(int index) {
return forwardList.remove(reverseIndex(index));
}
@Override
protected void removeRange(int fromIndex, int toIndex) {
subList(fromIndex, toIndex).clear();
}
@Override
public T set(int index, @Nullable T element) {
return forwardList.set(reverseIndex(index), element);
}
@Override
public T get(int index) {
return forwardList.get(reverseIndex(index));
}
@Override
public int size() {
return forwardList.size();
}
@Override
public List<T> subList(int fromIndex, int toIndex) { | // Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static int checkElementIndex(int index, int size) {
// return checkElementIndex(index, size, "index");
// }
//
// Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static <T> T checkNotNull(T reference) {
// if (reference == null) {
// throw new NullPointerException();
// }
// return reference;
// }
//
// Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static int checkPositionIndex(int index, int size) {
// return checkPositionIndex(index, size, "index");
// }
//
// Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static void checkPositionIndexes(int start, int end, int size) {
// // Carefully optimized for execution by hotspot (explanatory comment above)
// if (start < 0 || end < start || end > size) {
// throw new IndexOutOfBoundsException(badPositionIndexes(start, end, size));
// }
// }
//
// Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static void checkState(boolean expression) {
// if (!expression) {
// throw new IllegalStateException();
// }
// }
// Path: src/main/java/com/fernandocejas/arrow/collections/ReverseList.java
import java.util.AbstractList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.NoSuchElementException;
import org.jetbrains.annotations.Nullable;
import static com.fernandocejas.arrow.checks.Preconditions.checkElementIndex;
import static com.fernandocejas.arrow.checks.Preconditions.checkNotNull;
import static com.fernandocejas.arrow.checks.Preconditions.checkPositionIndex;
import static com.fernandocejas.arrow.checks.Preconditions.checkPositionIndexes;
import static com.fernandocejas.arrow.checks.Preconditions.checkState;
forwardList.clear();
}
@Override
public T remove(int index) {
return forwardList.remove(reverseIndex(index));
}
@Override
protected void removeRange(int fromIndex, int toIndex) {
subList(fromIndex, toIndex).clear();
}
@Override
public T set(int index, @Nullable T element) {
return forwardList.set(reverseIndex(index), element);
}
@Override
public T get(int index) {
return forwardList.get(reverseIndex(index));
}
@Override
public int size() {
return forwardList.size();
}
@Override
public List<T> subList(int fromIndex, int toIndex) { | checkPositionIndexes(fromIndex, toIndex, size()); |
android10/arrow | src/main/java/com/fernandocejas/arrow/collections/ReverseList.java | // Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static int checkElementIndex(int index, int size) {
// return checkElementIndex(index, size, "index");
// }
//
// Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static <T> T checkNotNull(T reference) {
// if (reference == null) {
// throw new NullPointerException();
// }
// return reference;
// }
//
// Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static int checkPositionIndex(int index, int size) {
// return checkPositionIndex(index, size, "index");
// }
//
// Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static void checkPositionIndexes(int start, int end, int size) {
// // Carefully optimized for execution by hotspot (explanatory comment above)
// if (start < 0 || end < start || end > size) {
// throw new IndexOutOfBoundsException(badPositionIndexes(start, end, size));
// }
// }
//
// Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static void checkState(boolean expression) {
// if (!expression) {
// throw new IllegalStateException();
// }
// }
| import java.util.AbstractList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.NoSuchElementException;
import org.jetbrains.annotations.Nullable;
import static com.fernandocejas.arrow.checks.Preconditions.checkElementIndex;
import static com.fernandocejas.arrow.checks.Preconditions.checkNotNull;
import static com.fernandocejas.arrow.checks.Preconditions.checkPositionIndex;
import static com.fernandocejas.arrow.checks.Preconditions.checkPositionIndexes;
import static com.fernandocejas.arrow.checks.Preconditions.checkState; | return forwardIterator.previous();
}
@Override
public int nextIndex() {
return reversePosition(forwardIterator.nextIndex());
}
@Override
public T previous() {
if (!hasPrevious()) {
throw new NoSuchElementException();
}
canRemoveOrSet = true;
return forwardIterator.next();
}
@Override
public int previousIndex() {
return nextIndex() - 1;
}
@Override
public void remove() {
forwardIterator.remove();
canRemoveOrSet = false;
}
@Override
public void set(T e) { | // Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static int checkElementIndex(int index, int size) {
// return checkElementIndex(index, size, "index");
// }
//
// Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static <T> T checkNotNull(T reference) {
// if (reference == null) {
// throw new NullPointerException();
// }
// return reference;
// }
//
// Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static int checkPositionIndex(int index, int size) {
// return checkPositionIndex(index, size, "index");
// }
//
// Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static void checkPositionIndexes(int start, int end, int size) {
// // Carefully optimized for execution by hotspot (explanatory comment above)
// if (start < 0 || end < start || end > size) {
// throw new IndexOutOfBoundsException(badPositionIndexes(start, end, size));
// }
// }
//
// Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static void checkState(boolean expression) {
// if (!expression) {
// throw new IllegalStateException();
// }
// }
// Path: src/main/java/com/fernandocejas/arrow/collections/ReverseList.java
import java.util.AbstractList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.NoSuchElementException;
import org.jetbrains.annotations.Nullable;
import static com.fernandocejas.arrow.checks.Preconditions.checkElementIndex;
import static com.fernandocejas.arrow.checks.Preconditions.checkNotNull;
import static com.fernandocejas.arrow.checks.Preconditions.checkPositionIndex;
import static com.fernandocejas.arrow.checks.Preconditions.checkPositionIndexes;
import static com.fernandocejas.arrow.checks.Preconditions.checkState;
return forwardIterator.previous();
}
@Override
public int nextIndex() {
return reversePosition(forwardIterator.nextIndex());
}
@Override
public T previous() {
if (!hasPrevious()) {
throw new NoSuchElementException();
}
canRemoveOrSet = true;
return forwardIterator.next();
}
@Override
public int previousIndex() {
return nextIndex() - 1;
}
@Override
public void remove() {
forwardIterator.remove();
canRemoveOrSet = false;
}
@Override
public void set(T e) { | checkState(canRemoveOrSet); |
android10/arrow | src/main/java/com/fernandocejas/arrow/collections/Partition.java | // Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static int checkElementIndex(int index, int size) {
// return checkElementIndex(index, size, "index");
// }
| import java.util.AbstractList;
import java.util.List;
import static com.fernandocejas.arrow.checks.Preconditions.checkElementIndex; | /**
* Copyright (C) 2007 The Guava Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.fernandocejas.arrow.collections;
class Partition<T> extends AbstractList<List<T>> {
final List<T> list;
final int size;
Partition(List<T> list, int size) {
this.list = list;
this.size = size;
}
@Override
public List<T> get(int index) { | // Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static int checkElementIndex(int index, int size) {
// return checkElementIndex(index, size, "index");
// }
// Path: src/main/java/com/fernandocejas/arrow/collections/Partition.java
import java.util.AbstractList;
import java.util.List;
import static com.fernandocejas.arrow.checks.Preconditions.checkElementIndex;
/**
* Copyright (C) 2007 The Guava Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.fernandocejas.arrow.collections;
class Partition<T> extends AbstractList<List<T>> {
final List<T> list;
final int size;
Partition(List<T> list, int size) {
this.list = list;
this.size = size;
}
@Override
public List<T> get(int index) { | checkElementIndex(index, size()); |
android10/arrow | src/main/java/com/fernandocejas/arrow/collections/Lists.java | // Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static void checkArgument(boolean expression) {
// if (!expression) {
// throw new IllegalArgumentException();
// }
// }
//
// Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static <T> T checkNotNull(T reference) {
// if (reference == null) {
// throw new NullPointerException();
// }
// return reference;
// }
| import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.RandomAccess;
import static com.fernandocejas.arrow.checks.Preconditions.checkArgument;
import static com.fernandocejas.arrow.checks.Preconditions.checkNotNull; | /**
* Copyright (C) 2007 The Guava Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.fernandocejas.arrow.collections;
/**
* Static utility methods pertaining to {@link List} instances.
*
* <p>See the Guava User Guide article on <a href=
* "http://code.google.com/p/guava-libraries/wiki/CollectionUtilitiesExplained#Lists">
* {@code Lists}</a>.
*
* @author Kevin Bourrillion
* @author Mike Bostock
* @author Louis Wasserman
* @since 2.0 (imported from Google Collections Library)
*
* <p><b>This class contains code derived from <a href="https://github.com/google/guava">Google Guava</a></b>
*/
public final class Lists {
/**
* Creates a <i>mutable</i> {@code ArrayList} instance containing the given
* elements.
*
* <p><b>Note:</b> essentially the only reason to use this method is when you
* will need to add or remove elements later. If any elements
* might be null, or you need support for {@link List#set(int, Object)}, use
* {@link java.util.Arrays#asList}.
*
* <p>Note that even when you do need the ability to add or remove, this method
* provides only a tiny bit of syntactic sugar for {@code newArrayList(}{@link
* java.util.Arrays#asList asList}{@code (...))}, or for creating an empty list then
* calling {@link Collections#addAll}. This method is not actually very useful
* and will likely be deprecated in the future.
*/
@SuppressWarnings({"unchecked", "PMD.LooseCoupling"})
public static <E> ArrayList<E> newArrayList(E... elements) { | // Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static void checkArgument(boolean expression) {
// if (!expression) {
// throw new IllegalArgumentException();
// }
// }
//
// Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static <T> T checkNotNull(T reference) {
// if (reference == null) {
// throw new NullPointerException();
// }
// return reference;
// }
// Path: src/main/java/com/fernandocejas/arrow/collections/Lists.java
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.RandomAccess;
import static com.fernandocejas.arrow.checks.Preconditions.checkArgument;
import static com.fernandocejas.arrow.checks.Preconditions.checkNotNull;
/**
* Copyright (C) 2007 The Guava Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.fernandocejas.arrow.collections;
/**
* Static utility methods pertaining to {@link List} instances.
*
* <p>See the Guava User Guide article on <a href=
* "http://code.google.com/p/guava-libraries/wiki/CollectionUtilitiesExplained#Lists">
* {@code Lists}</a>.
*
* @author Kevin Bourrillion
* @author Mike Bostock
* @author Louis Wasserman
* @since 2.0 (imported from Google Collections Library)
*
* <p><b>This class contains code derived from <a href="https://github.com/google/guava">Google Guava</a></b>
*/
public final class Lists {
/**
* Creates a <i>mutable</i> {@code ArrayList} instance containing the given
* elements.
*
* <p><b>Note:</b> essentially the only reason to use this method is when you
* will need to add or remove elements later. If any elements
* might be null, or you need support for {@link List#set(int, Object)}, use
* {@link java.util.Arrays#asList}.
*
* <p>Note that even when you do need the ability to add or remove, this method
* provides only a tiny bit of syntactic sugar for {@code newArrayList(}{@link
* java.util.Arrays#asList asList}{@code (...))}, or for creating an empty list then
* calling {@link Collections#addAll}. This method is not actually very useful
* and will likely be deprecated in the future.
*/
@SuppressWarnings({"unchecked", "PMD.LooseCoupling"})
public static <E> ArrayList<E> newArrayList(E... elements) { | checkNotNull(elements); |
android10/arrow | src/main/java/com/fernandocejas/arrow/collections/Lists.java | // Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static void checkArgument(boolean expression) {
// if (!expression) {
// throw new IllegalArgumentException();
// }
// }
//
// Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static <T> T checkNotNull(T reference) {
// if (reference == null) {
// throw new NullPointerException();
// }
// return reference;
// }
| import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.RandomAccess;
import static com.fernandocejas.arrow.checks.Preconditions.checkArgument;
import static com.fernandocejas.arrow.checks.Preconditions.checkNotNull; | return list;
}
/**
* Used to avoid http://bugs.sun.com/view_bug.do?bug_id=6558557
*/
static <T> List<T> cast(Iterable<T> iterable) {
return (List<T>) iterable;
}
/**
* Returns consecutive {@linkplain List#subList(int, int) sublists} of a list,
* each of the same size (the final list may be smaller). For example,
* partitioning a list containing {@code [a, b, c, d, e]} with a partition
* size of 3 yields {@code [[a, b, c], [d, e]]} -- an outer list containing
* two inner lists of three and two elements, all in the original order.
*
* <p>The outer list is unmodifiable, but reflects the latest state of the
* source list. The inner lists are sublist views of the original list,
* produced on demand using {@link List#subList(int, int)}, and are subject
* to all the usual caveats about modification as explained in that API.
*
* @param list the list to return consecutive sublists of
* @param size the desired size of each sublist (the last may be
* smaller)
* @return a list of consecutive sublists
* @throws IllegalArgumentException if {@code partitionSize} is nonpositive
*/
public static <T> List<List<T>> partition(List<T> list, int size) {
checkNotNull(list); | // Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static void checkArgument(boolean expression) {
// if (!expression) {
// throw new IllegalArgumentException();
// }
// }
//
// Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static <T> T checkNotNull(T reference) {
// if (reference == null) {
// throw new NullPointerException();
// }
// return reference;
// }
// Path: src/main/java/com/fernandocejas/arrow/collections/Lists.java
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.RandomAccess;
import static com.fernandocejas.arrow.checks.Preconditions.checkArgument;
import static com.fernandocejas.arrow.checks.Preconditions.checkNotNull;
return list;
}
/**
* Used to avoid http://bugs.sun.com/view_bug.do?bug_id=6558557
*/
static <T> List<T> cast(Iterable<T> iterable) {
return (List<T>) iterable;
}
/**
* Returns consecutive {@linkplain List#subList(int, int) sublists} of a list,
* each of the same size (the final list may be smaller). For example,
* partitioning a list containing {@code [a, b, c, d, e]} with a partition
* size of 3 yields {@code [[a, b, c], [d, e]]} -- an outer list containing
* two inner lists of three and two elements, all in the original order.
*
* <p>The outer list is unmodifiable, but reflects the latest state of the
* source list. The inner lists are sublist views of the original list,
* produced on demand using {@link List#subList(int, int)}, and are subject
* to all the usual caveats about modification as explained in that API.
*
* @param list the list to return consecutive sublists of
* @param size the desired size of each sublist (the last may be
* smaller)
* @return a list of consecutive sublists
* @throws IllegalArgumentException if {@code partitionSize} is nonpositive
*/
public static <T> List<List<T>> partition(List<T> list, int size) {
checkNotNull(list); | checkArgument(size > 0); |
android10/arrow | src/main/java/com/fernandocejas/arrow/collections/CollectPreconditions.java | // Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static void checkState(boolean expression) {
// if (!expression) {
// throw new IllegalStateException();
// }
// }
| import static com.fernandocejas.arrow.checks.Preconditions.checkState; | /**
* Copyright (C) 2007 The Guava Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.fernandocejas.arrow.collections;
/**
* Precondition checks useful in collection implementations.
*/
public final class CollectPreconditions {
public static void checkIndexNonnegative(int value) {
if (value < 0) {
throw new IndexOutOfBoundsException("value (" + value
+ ") must not be negative");
}
}
public static int checkNonnegative(int value, String name) {
if (value < 0) {
throw new IllegalArgumentException(name + " cannot be negative but was: " + value);
}
return value;
}
/**
* Precondition tester for {@code Iterator.remove()} that throws an exception with a consistent
* error message.
*/
static void checkRemove(boolean canRemove) { | // Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static void checkState(boolean expression) {
// if (!expression) {
// throw new IllegalStateException();
// }
// }
// Path: src/main/java/com/fernandocejas/arrow/collections/CollectPreconditions.java
import static com.fernandocejas.arrow.checks.Preconditions.checkState;
/**
* Copyright (C) 2007 The Guava Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.fernandocejas.arrow.collections;
/**
* Precondition checks useful in collection implementations.
*/
public final class CollectPreconditions {
public static void checkIndexNonnegative(int value) {
if (value < 0) {
throw new IndexOutOfBoundsException("value (" + value
+ ") must not be negative");
}
}
public static int checkNonnegative(int value, String name) {
if (value < 0) {
throw new IllegalArgumentException(name + " cannot be negative but was: " + value);
}
return value;
}
/**
* Precondition tester for {@code Iterator.remove()} that throws an exception with a consistent
* error message.
*/
static void checkRemove(boolean canRemove) { | checkState(canRemove, "no calls to next() since the last call to remove()"); |
lemire/javaewah | src/main/java/com/googlecode/javaewah32/ReverseIntIterator32.java | // Path: src/main/java/com/googlecode/javaewah/IntIterator.java
// public interface IntIterator {
//
// /**
// * Is there more?
// *
// * @return true, if there is more, false otherwise
// */
// boolean hasNext();
//
// /**
// * Return the next integer
// *
// * @return the integer
// */
// int next();
// }
//
// Path: src/main/java/com/googlecode/javaewah32/EWAHCompressedBitmap32.java
// public static final int WORD_IN_BITS = 32;
| import static com.googlecode.javaewah32.EWAHCompressedBitmap32.WORD_IN_BITS;
import com.googlecode.javaewah.IntIterator; | }
@Override
public int next() {
final int answer;
if (literalHasNext()) {
final int t = this.word & -this.word;
answer = this.literalPosition - Integer.bitCount(t - 1);
this.word ^= t;
} else {
answer = this.position--;
}
this.hasNext = this.moveToPreviousRLW();
return answer;
}
private boolean moveToPreviousRLW() {
while (!literalHasNext() && !runningHasNext()) {
if (!this.ewahIter.hasPrevious()) {
return false;
}
setRLW(this.ewahIter.previous());
}
return true;
}
private void setRLW(RunningLengthWord32 rlw) {
this.wordLength = rlw.getNumberOfLiteralWords();
this.wordPosition = this.ewahIter.position();
this.position = this.runningLength; | // Path: src/main/java/com/googlecode/javaewah/IntIterator.java
// public interface IntIterator {
//
// /**
// * Is there more?
// *
// * @return true, if there is more, false otherwise
// */
// boolean hasNext();
//
// /**
// * Return the next integer
// *
// * @return the integer
// */
// int next();
// }
//
// Path: src/main/java/com/googlecode/javaewah32/EWAHCompressedBitmap32.java
// public static final int WORD_IN_BITS = 32;
// Path: src/main/java/com/googlecode/javaewah32/ReverseIntIterator32.java
import static com.googlecode.javaewah32.EWAHCompressedBitmap32.WORD_IN_BITS;
import com.googlecode.javaewah.IntIterator;
}
@Override
public int next() {
final int answer;
if (literalHasNext()) {
final int t = this.word & -this.word;
answer = this.literalPosition - Integer.bitCount(t - 1);
this.word ^= t;
} else {
answer = this.position--;
}
this.hasNext = this.moveToPreviousRLW();
return answer;
}
private boolean moveToPreviousRLW() {
while (!literalHasNext() && !runningHasNext()) {
if (!this.ewahIter.hasPrevious()) {
return false;
}
setRLW(this.ewahIter.previous());
}
return true;
}
private void setRLW(RunningLengthWord32 rlw) {
this.wordLength = rlw.getNumberOfLiteralWords();
this.wordPosition = this.ewahIter.position();
this.position = this.runningLength; | this.runningLength -= WORD_IN_BITS * (rlw.getRunningLength() + this.wordLength); |
lemire/javaewah | src/main/java/com/googlecode/javaewah32/symmetric/ThresholdFuncBitmap32.java | // Path: src/main/java/com/googlecode/javaewah32/BitmapStorage32.java
// public interface BitmapStorage32 {
//
// /**
// * Adding words directly to the bitmap (for expert use).
// *
// * This is normally how you add data to the array. So you add bits in
// * streams of 8*8 bits.
// *
// * @param newData the word
// */
// void addWord(final int newData);
//
// /**
// * Adding literal words directly to the bitmap (for expert use).
// *
// * @param newData the word
// */
// void addLiteralWord(final int newData);
//
// /**
// * if you have several literal words to copy over, this might be faster.
// *
// * @param buffer the buffer wrapping the literal words
// * @param start the starting point in the array
// * @param number the number of literal words to add
// */
// void addStreamOfLiteralWords(final Buffer32 buffer, final int start,
// final int number);
//
// /**
// * For experts: You want to add many zeroes or ones? This is the method
// * you use.
// *
// * @param v zeros or ones
// * @param number how many to words add
// */
// void addStreamOfEmptyWords(final boolean v, final int number);
//
// /**
// * Like "addStreamOfLiteralWords" but negates the words being added.
// *
// * @param buffer the buffer wrapping the literal words
// * @param start the starting point in the array
// * @param number the number of literal words to add
// */
// void addStreamOfNegatedLiteralWords(final Buffer32 buffer, final int start,
// final int number);
//
// /**
// * Empties the container.
// */
// void clear();
//
// /**
// * Sets the size in bits of the bitmap as an *uncompressed* bitmap.
// * Normally, this is used to reduce the size of the bitmaps within
// * the scope of the last word. Specifically, this means that
// * (sizeInBits()+31)/32 must be equal to (size+31)/32.
// * If needed, the bitmap can be further padded with zeroes.
// *
// * @param size the size in bits
// */
// void setSizeInBitsWithinLastWord(final int size);
// }
| import com.googlecode.javaewah32.BitmapStorage32;
import java.util.Arrays; | package com.googlecode.javaewah32.symmetric;
/**
* A threshold Boolean function returns true if the number of true values exceed
* a threshold. It is a symmetric Boolean function.
*
* This class implements an algorithm described in the following paper:
*
* Owen Kaser and Daniel Lemire, Compressed bitmap indexes: beyond unions and intersections
* <a href="http://arxiv.org/abs/1402.4466">http://arxiv.org/abs/1402.4466</a>
*
* It is not thread safe: you should use one object per thread.
*
* @author Daniel Lemire
* @see <a
* href="http://en.wikipedia.org/wiki/Symmetric_Boolean_function">http://en.wikipedia.org/wiki/Symmetric_Boolean_function</a>
* @since 0.8.2
*/
public final class ThresholdFuncBitmap32 extends UpdateableBitmapFunction32 {
private final int min;
private int[] buffers;
private int bufferUsed;
private final int[] bufcounters = new int[64];
private static final int[] zeroes64 = new int[64];
/**
* Construction a threshold function with a given threshold
*
* @param min threshold
*/
public ThresholdFuncBitmap32(final int min) {
super();
this.min = min;
this.buffers = new int[16];
this.bufferUsed = 0;
}
@Override | // Path: src/main/java/com/googlecode/javaewah32/BitmapStorage32.java
// public interface BitmapStorage32 {
//
// /**
// * Adding words directly to the bitmap (for expert use).
// *
// * This is normally how you add data to the array. So you add bits in
// * streams of 8*8 bits.
// *
// * @param newData the word
// */
// void addWord(final int newData);
//
// /**
// * Adding literal words directly to the bitmap (for expert use).
// *
// * @param newData the word
// */
// void addLiteralWord(final int newData);
//
// /**
// * if you have several literal words to copy over, this might be faster.
// *
// * @param buffer the buffer wrapping the literal words
// * @param start the starting point in the array
// * @param number the number of literal words to add
// */
// void addStreamOfLiteralWords(final Buffer32 buffer, final int start,
// final int number);
//
// /**
// * For experts: You want to add many zeroes or ones? This is the method
// * you use.
// *
// * @param v zeros or ones
// * @param number how many to words add
// */
// void addStreamOfEmptyWords(final boolean v, final int number);
//
// /**
// * Like "addStreamOfLiteralWords" but negates the words being added.
// *
// * @param buffer the buffer wrapping the literal words
// * @param start the starting point in the array
// * @param number the number of literal words to add
// */
// void addStreamOfNegatedLiteralWords(final Buffer32 buffer, final int start,
// final int number);
//
// /**
// * Empties the container.
// */
// void clear();
//
// /**
// * Sets the size in bits of the bitmap as an *uncompressed* bitmap.
// * Normally, this is used to reduce the size of the bitmaps within
// * the scope of the last word. Specifically, this means that
// * (sizeInBits()+31)/32 must be equal to (size+31)/32.
// * If needed, the bitmap can be further padded with zeroes.
// *
// * @param size the size in bits
// */
// void setSizeInBitsWithinLastWord(final int size);
// }
// Path: src/main/java/com/googlecode/javaewah32/symmetric/ThresholdFuncBitmap32.java
import com.googlecode.javaewah32.BitmapStorage32;
import java.util.Arrays;
package com.googlecode.javaewah32.symmetric;
/**
* A threshold Boolean function returns true if the number of true values exceed
* a threshold. It is a symmetric Boolean function.
*
* This class implements an algorithm described in the following paper:
*
* Owen Kaser and Daniel Lemire, Compressed bitmap indexes: beyond unions and intersections
* <a href="http://arxiv.org/abs/1402.4466">http://arxiv.org/abs/1402.4466</a>
*
* It is not thread safe: you should use one object per thread.
*
* @author Daniel Lemire
* @see <a
* href="http://en.wikipedia.org/wiki/Symmetric_Boolean_function">http://en.wikipedia.org/wiki/Symmetric_Boolean_function</a>
* @since 0.8.2
*/
public final class ThresholdFuncBitmap32 extends UpdateableBitmapFunction32 {
private final int min;
private int[] buffers;
private int bufferUsed;
private final int[] bufcounters = new int[64];
private static final int[] zeroes64 = new int[64];
/**
* Construction a threshold function with a given threshold
*
* @param min threshold
*/
public ThresholdFuncBitmap32(final int min) {
super();
this.min = min;
this.buffers = new int[16];
this.bufferUsed = 0;
}
@Override | public void dispatch(BitmapStorage32 out, int runBegin, int runend) { |
lemire/javaewah | src/main/java/com/googlecode/javaewah32/ClearIntIterator32.java | // Path: src/main/java/com/googlecode/javaewah/IntIterator.java
// public interface IntIterator {
//
// /**
// * Is there more?
// *
// * @return true, if there is more, false otherwise
// */
// boolean hasNext();
//
// /**
// * Return the next integer
// *
// * @return the integer
// */
// int next();
// }
//
// Path: src/main/java/com/googlecode/javaewah32/EWAHCompressedBitmap32.java
// public static final int WORD_IN_BITS = 32;
| import com.googlecode.javaewah.IntIterator;
import static com.googlecode.javaewah32.EWAHCompressedBitmap32.WORD_IN_BITS; | while (!runningHasNext() && !literalHasNext()) {
if (!this.ewahIter.hasNext()) {
return false;
}
setRunningLengthWord(this.ewahIter.next());
}
return true;
}
@Override
public boolean hasNext() {
return this.hasNext;
}
@Override
public int next() {
final int answer;
if (runningHasNext()) {
answer = this.position++;
} else {
final int t = this.word & -this.word;
answer = this.literalPosition + Integer.bitCount(t - 1);
this.word ^= t;
}
this.hasNext = this.moveToNext();
return answer;
}
private void setRunningLengthWord(RunningLengthWord32 rlw) {
this.runningLength = Math.min(this.sizeInBits, | // Path: src/main/java/com/googlecode/javaewah/IntIterator.java
// public interface IntIterator {
//
// /**
// * Is there more?
// *
// * @return true, if there is more, false otherwise
// */
// boolean hasNext();
//
// /**
// * Return the next integer
// *
// * @return the integer
// */
// int next();
// }
//
// Path: src/main/java/com/googlecode/javaewah32/EWAHCompressedBitmap32.java
// public static final int WORD_IN_BITS = 32;
// Path: src/main/java/com/googlecode/javaewah32/ClearIntIterator32.java
import com.googlecode.javaewah.IntIterator;
import static com.googlecode.javaewah32.EWAHCompressedBitmap32.WORD_IN_BITS;
while (!runningHasNext() && !literalHasNext()) {
if (!this.ewahIter.hasNext()) {
return false;
}
setRunningLengthWord(this.ewahIter.next());
}
return true;
}
@Override
public boolean hasNext() {
return this.hasNext;
}
@Override
public int next() {
final int answer;
if (runningHasNext()) {
answer = this.position++;
} else {
final int t = this.word & -this.word;
answer = this.literalPosition + Integer.bitCount(t - 1);
this.word ^= t;
}
this.hasNext = this.moveToNext();
return answer;
}
private void setRunningLengthWord(RunningLengthWord32 rlw) {
this.runningLength = Math.min(this.sizeInBits, | WORD_IN_BITS * rlw.getRunningLength() + this.position); |
lemire/javaewah | src/main/java/com/googlecode/javaewah32/IteratorAggregation32.java | // Path: src/main/java/com/googlecode/javaewah/CloneableIterator.java
// public interface CloneableIterator<E> extends Cloneable {
//
// /**
// * @return whether there is more
// */
// boolean hasNext();
//
// /**
// * @return the next element
// */
// E next();
//
// /**
// * @return a copy
// * @throws CloneNotSupportedException this should never happen in practice
// */
// CloneableIterator<E> clone() throws CloneNotSupportedException;
//
// }
| import com.googlecode.javaewah.CloneableIterator;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList; | int l = i.getRunningLength();
if (pos + l > bitmap.length) {
if (!i.getRunningBit()) {
for (int k = pos; k < bitmap.length; ++k)
bitmap[k] = 0;
}
i.discardFirstWords(howMany);
return bitmap.length;
}
if (!i.getRunningBit())
for (int k = pos; k < pos + l; ++k)
bitmap[k] = 0;
pos += l;
for (int k = 0; pos < bitmap.length; ++k)
bitmap[pos++] &= i.getLiteralWordAt(k);
i.discardFirstWords(howMany);
return pos;
}
}
return pos;
}
/**
* An optimization option. Larger values may improve speed, but at the
* expense of memory.
*/
public static final int DEFAULT_MAX_BUF_SIZE = 65536;
}
| // Path: src/main/java/com/googlecode/javaewah/CloneableIterator.java
// public interface CloneableIterator<E> extends Cloneable {
//
// /**
// * @return whether there is more
// */
// boolean hasNext();
//
// /**
// * @return the next element
// */
// E next();
//
// /**
// * @return a copy
// * @throws CloneNotSupportedException this should never happen in practice
// */
// CloneableIterator<E> clone() throws CloneNotSupportedException;
//
// }
// Path: src/main/java/com/googlecode/javaewah32/IteratorAggregation32.java
import com.googlecode.javaewah.CloneableIterator;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
int l = i.getRunningLength();
if (pos + l > bitmap.length) {
if (!i.getRunningBit()) {
for (int k = pos; k < bitmap.length; ++k)
bitmap[k] = 0;
}
i.discardFirstWords(howMany);
return bitmap.length;
}
if (!i.getRunningBit())
for (int k = pos; k < pos + l; ++k)
bitmap[k] = 0;
pos += l;
for (int k = 0; pos < bitmap.length; ++k)
bitmap[pos++] &= i.getLiteralWordAt(k);
i.discardFirstWords(howMany);
return pos;
}
}
return pos;
}
/**
* An optimization option. Larger values may improve speed, but at the
* expense of memory.
*/
public static final int DEFAULT_MAX_BUF_SIZE = 65536;
}
| class ORIt implements CloneableIterator<EWAHIterator32> { |
lemire/javaewah | src/main/java/com/googlecode/javaewah32/IntIteratorImpl32.java | // Path: src/main/java/com/googlecode/javaewah/IntIterator.java
// public interface IntIterator {
//
// /**
// * Is there more?
// *
// * @return true, if there is more, false otherwise
// */
// boolean hasNext();
//
// /**
// * Return the next integer
// *
// * @return the integer
// */
// int next();
// }
//
// Path: src/main/java/com/googlecode/javaewah32/EWAHCompressedBitmap32.java
// public static final int WORD_IN_BITS = 32;
| import static com.googlecode.javaewah32.EWAHCompressedBitmap32.WORD_IN_BITS;
import com.googlecode.javaewah.IntIterator; | public boolean moveToNext() {
while (!runningHasNext() && !literalHasNext()) {
if (!this.ewahIter.hasNext()) {
return false;
}
setRunningLengthWord(this.ewahIter.next());
}
return true;
}
@Override
public boolean hasNext() {
return this.hasnext;
}
@Override
public int next() {
final int answer;
if (runningHasNext()) {
answer = this.position++;
} else {
final int t = this.word & -this.word;
answer = this.literalPosition + Integer.bitCount(t - 1);
this.word ^= t;
}
this.hasnext = this.moveToNext();
return answer;
}
private void setRunningLengthWord(RunningLengthWord32 rlw) { | // Path: src/main/java/com/googlecode/javaewah/IntIterator.java
// public interface IntIterator {
//
// /**
// * Is there more?
// *
// * @return true, if there is more, false otherwise
// */
// boolean hasNext();
//
// /**
// * Return the next integer
// *
// * @return the integer
// */
// int next();
// }
//
// Path: src/main/java/com/googlecode/javaewah32/EWAHCompressedBitmap32.java
// public static final int WORD_IN_BITS = 32;
// Path: src/main/java/com/googlecode/javaewah32/IntIteratorImpl32.java
import static com.googlecode.javaewah32.EWAHCompressedBitmap32.WORD_IN_BITS;
import com.googlecode.javaewah.IntIterator;
public boolean moveToNext() {
while (!runningHasNext() && !literalHasNext()) {
if (!this.ewahIter.hasNext()) {
return false;
}
setRunningLengthWord(this.ewahIter.next());
}
return true;
}
@Override
public boolean hasNext() {
return this.hasnext;
}
@Override
public int next() {
final int answer;
if (runningHasNext()) {
answer = this.position++;
} else {
final int t = this.word & -this.word;
answer = this.literalPosition + Integer.bitCount(t - 1);
this.word ^= t;
}
this.hasnext = this.moveToNext();
return answer;
}
private void setRunningLengthWord(RunningLengthWord32 rlw) { | this.runningLength = WORD_IN_BITS * rlw.getRunningLength() |
lemire/javaewah | src/main/java/com/googlecode/javaewah/IntIteratorOverIteratingRLW.java | // Path: src/main/java/com/googlecode/javaewah/EWAHCompressedBitmap.java
// public static final int WORD_IN_BITS = 64;
| import static com.googlecode.javaewah.EWAHCompressedBitmap.WORD_IN_BITS; | private boolean moveToNext() {
while (!runningHasNext() && !literalHasNext()) {
if (this.parent.next())
setupForCurrentRunningLengthWord();
else
return false;
}
return true;
}
@Override
public boolean hasNext() {
return this.hasNext;
}
@Override
public final int next() {
final int answer;
if (runningHasNext()) {
answer = this.position++;
} else {
final long t = this.word & -this.word;
answer = this.literalPosition + Long.bitCount(t - 1);
this.word ^= t;
}
this.hasNext = this.moveToNext();
return answer;
}
private void setupForCurrentRunningLengthWord() { | // Path: src/main/java/com/googlecode/javaewah/EWAHCompressedBitmap.java
// public static final int WORD_IN_BITS = 64;
// Path: src/main/java/com/googlecode/javaewah/IntIteratorOverIteratingRLW.java
import static com.googlecode.javaewah.EWAHCompressedBitmap.WORD_IN_BITS;
private boolean moveToNext() {
while (!runningHasNext() && !literalHasNext()) {
if (this.parent.next())
setupForCurrentRunningLengthWord();
else
return false;
}
return true;
}
@Override
public boolean hasNext() {
return this.hasNext;
}
@Override
public final int next() {
final int answer;
if (runningHasNext()) {
answer = this.position++;
} else {
final long t = this.word & -this.word;
answer = this.literalPosition + Long.bitCount(t - 1);
this.word ^= t;
}
this.hasNext = this.moveToNext();
return answer;
}
private void setupForCurrentRunningLengthWord() { | this.runningLength = WORD_IN_BITS * (int) this.parent.getRunningLength() + this.position; |
lemire/javaewah | src/test/java/com/googlecode/javaewah32/IteratorAggregation32Test.java | // Path: src/main/java/com/googlecode/javaewah32/EWAHCompressedBitmap32.java
// static int maxSizeInBits(final EWAHCompressedBitmap32... bitmaps) {
// int maxSizeInBits = 0;
// for(EWAHCompressedBitmap32 bitmap : bitmaps) {
// maxSizeInBits = Math.max(maxSizeInBits, bitmap.sizeInBits());
// }
// return maxSizeInBits;
// }
//
// Path: src/test/java/com/googlecode/javaewah/synth/ClusteredDataGenerator.java
// public class ClusteredDataGenerator {
//
// /**
// *
// */
// public ClusteredDataGenerator() {
// this.unidg = new UniformDataGenerator();
// }
//
// /**
// * @param seed random seed
// */
// public ClusteredDataGenerator(final int seed) {
// this.unidg = new UniformDataGenerator(seed);
// }
//
// /**
// * generates randomly N distinct integers from 0 to Max.
// *
// * @param N number of integers
// * @param Max maximum integer value
// * @return a randomly generated array
// */
// public int[] generateClustered(int N, int Max) {
// int[] array = new int[N];
// fillClustered(array, 0, N, 0, Max);
// return array;
// }
//
// void fillClustered(int[] array, int offset, int length, int Min, int Max) {
// final int range = Max - Min;
// if ((range == length) || (length <= 10)) {
// fillUniform(array, offset, length, Min, Max);
// return;
// }
// final int cut = length
// / 2
// + ((range - length - 1 > 0) ? this.unidg.rand
// .nextInt(range - length - 1) : 0);
// final double p = this.unidg.rand.nextDouble();
// if (p < 0.25) {
// fillUniform(array, offset, length / 2, Min, Min + cut);
// fillClustered(array, offset + length / 2, length
// - length / 2, Min + cut, Max);
// } else if (p < 0.5) {
// fillClustered(array, offset, length / 2, Min, Min + cut);
// fillUniform(array, offset + length / 2, length - length
// / 2, Min + cut, Max);
// } else {
// fillClustered(array, offset, length / 2, Min, Min + cut);
// fillClustered(array, offset + length / 2, length
// - length / 2, Min + cut, Max);
// }
// }
//
// void fillUniform(int[] array, int offset, int length, int Min, int Max) {
// int[] v = this.unidg.generateUniform(length, Max - Min);
// for (int k = 0; k < v.length; ++k)
// array[k + offset] = Min + v[k];
// }
//
// private final UniformDataGenerator unidg;
// }
| import static com.googlecode.javaewah32.EWAHCompressedBitmap32.maxSizeInBits;
import static org.junit.Assert.assertTrue;
import java.util.Iterator;
import org.junit.Test;
import com.googlecode.javaewah.synth.ClusteredDataGenerator; | package com.googlecode.javaewah32;
/*
* Copyright 2009-2016, Daniel Lemire, Cliff Moon, David McIntosh, Robert Becho, Google Inc., Veronika Zenz, Owen Kaser, Gregory Ssi-Yan-Kai, Rory Graves
* Licensed under the Apache License, Version 2.0.
*/
/**
* Tests specifically for iterators.
*/
public class IteratorAggregation32Test {
/**
* @param N number of bitmaps to generate in each set
* @param nbr parameter determining the size of the arrays (in a log
* scale)
* @return an iterator over sets of bitmaps
*/
public static Iterator<EWAHCompressedBitmap32[]> getCollections(
final int N, final int nbr) { | // Path: src/main/java/com/googlecode/javaewah32/EWAHCompressedBitmap32.java
// static int maxSizeInBits(final EWAHCompressedBitmap32... bitmaps) {
// int maxSizeInBits = 0;
// for(EWAHCompressedBitmap32 bitmap : bitmaps) {
// maxSizeInBits = Math.max(maxSizeInBits, bitmap.sizeInBits());
// }
// return maxSizeInBits;
// }
//
// Path: src/test/java/com/googlecode/javaewah/synth/ClusteredDataGenerator.java
// public class ClusteredDataGenerator {
//
// /**
// *
// */
// public ClusteredDataGenerator() {
// this.unidg = new UniformDataGenerator();
// }
//
// /**
// * @param seed random seed
// */
// public ClusteredDataGenerator(final int seed) {
// this.unidg = new UniformDataGenerator(seed);
// }
//
// /**
// * generates randomly N distinct integers from 0 to Max.
// *
// * @param N number of integers
// * @param Max maximum integer value
// * @return a randomly generated array
// */
// public int[] generateClustered(int N, int Max) {
// int[] array = new int[N];
// fillClustered(array, 0, N, 0, Max);
// return array;
// }
//
// void fillClustered(int[] array, int offset, int length, int Min, int Max) {
// final int range = Max - Min;
// if ((range == length) || (length <= 10)) {
// fillUniform(array, offset, length, Min, Max);
// return;
// }
// final int cut = length
// / 2
// + ((range - length - 1 > 0) ? this.unidg.rand
// .nextInt(range - length - 1) : 0);
// final double p = this.unidg.rand.nextDouble();
// if (p < 0.25) {
// fillUniform(array, offset, length / 2, Min, Min + cut);
// fillClustered(array, offset + length / 2, length
// - length / 2, Min + cut, Max);
// } else if (p < 0.5) {
// fillClustered(array, offset, length / 2, Min, Min + cut);
// fillUniform(array, offset + length / 2, length - length
// / 2, Min + cut, Max);
// } else {
// fillClustered(array, offset, length / 2, Min, Min + cut);
// fillClustered(array, offset + length / 2, length
// - length / 2, Min + cut, Max);
// }
// }
//
// void fillUniform(int[] array, int offset, int length, int Min, int Max) {
// int[] v = this.unidg.generateUniform(length, Max - Min);
// for (int k = 0; k < v.length; ++k)
// array[k + offset] = Min + v[k];
// }
//
// private final UniformDataGenerator unidg;
// }
// Path: src/test/java/com/googlecode/javaewah32/IteratorAggregation32Test.java
import static com.googlecode.javaewah32.EWAHCompressedBitmap32.maxSizeInBits;
import static org.junit.Assert.assertTrue;
import java.util.Iterator;
import org.junit.Test;
import com.googlecode.javaewah.synth.ClusteredDataGenerator;
package com.googlecode.javaewah32;
/*
* Copyright 2009-2016, Daniel Lemire, Cliff Moon, David McIntosh, Robert Becho, Google Inc., Veronika Zenz, Owen Kaser, Gregory Ssi-Yan-Kai, Rory Graves
* Licensed under the Apache License, Version 2.0.
*/
/**
* Tests specifically for iterators.
*/
public class IteratorAggregation32Test {
/**
* @param N number of bitmaps to generate in each set
* @param nbr parameter determining the size of the arrays (in a log
* scale)
* @return an iterator over sets of bitmaps
*/
public static Iterator<EWAHCompressedBitmap32[]> getCollections(
final int N, final int nbr) { | final ClusteredDataGenerator cdg = new ClusteredDataGenerator( |
lemire/javaewah | src/test/java/com/googlecode/javaewah32/IteratorAggregation32Test.java | // Path: src/main/java/com/googlecode/javaewah32/EWAHCompressedBitmap32.java
// static int maxSizeInBits(final EWAHCompressedBitmap32... bitmaps) {
// int maxSizeInBits = 0;
// for(EWAHCompressedBitmap32 bitmap : bitmaps) {
// maxSizeInBits = Math.max(maxSizeInBits, bitmap.sizeInBits());
// }
// return maxSizeInBits;
// }
//
// Path: src/test/java/com/googlecode/javaewah/synth/ClusteredDataGenerator.java
// public class ClusteredDataGenerator {
//
// /**
// *
// */
// public ClusteredDataGenerator() {
// this.unidg = new UniformDataGenerator();
// }
//
// /**
// * @param seed random seed
// */
// public ClusteredDataGenerator(final int seed) {
// this.unidg = new UniformDataGenerator(seed);
// }
//
// /**
// * generates randomly N distinct integers from 0 to Max.
// *
// * @param N number of integers
// * @param Max maximum integer value
// * @return a randomly generated array
// */
// public int[] generateClustered(int N, int Max) {
// int[] array = new int[N];
// fillClustered(array, 0, N, 0, Max);
// return array;
// }
//
// void fillClustered(int[] array, int offset, int length, int Min, int Max) {
// final int range = Max - Min;
// if ((range == length) || (length <= 10)) {
// fillUniform(array, offset, length, Min, Max);
// return;
// }
// final int cut = length
// / 2
// + ((range - length - 1 > 0) ? this.unidg.rand
// .nextInt(range - length - 1) : 0);
// final double p = this.unidg.rand.nextDouble();
// if (p < 0.25) {
// fillUniform(array, offset, length / 2, Min, Min + cut);
// fillClustered(array, offset + length / 2, length
// - length / 2, Min + cut, Max);
// } else if (p < 0.5) {
// fillClustered(array, offset, length / 2, Min, Min + cut);
// fillUniform(array, offset + length / 2, length - length
// / 2, Min + cut, Max);
// } else {
// fillClustered(array, offset, length / 2, Min, Min + cut);
// fillClustered(array, offset + length / 2, length
// - length / 2, Min + cut, Max);
// }
// }
//
// void fillUniform(int[] array, int offset, int length, int Min, int Max) {
// int[] v = this.unidg.generateUniform(length, Max - Min);
// for (int k = 0; k < v.length; ++k)
// array[k + offset] = Min + v[k];
// }
//
// private final UniformDataGenerator unidg;
// }
| import static com.googlecode.javaewah32.EWAHCompressedBitmap32.maxSizeInBits;
import static org.junit.Assert.assertTrue;
import java.util.Iterator;
import org.junit.Test;
import com.googlecode.javaewah.synth.ClusteredDataGenerator; | this.sparsity += 3;
return ewah;
}
@Override
public void remove() {
// unimplemented
}
};
}
/**
*
*/
@Test
public void testAnd() {
for (int N = 1; N < 10; ++N) {
System.out.println("testAnd N = " + N);
Iterator<EWAHCompressedBitmap32[]> i = getCollections(
N, 3);
while (i.hasNext()) {
EWAHCompressedBitmap32[] x = i.next();
EWAHCompressedBitmap32 tanswer = EWAHCompressedBitmap32
.and(x);
EWAHCompressedBitmap32 x1 = IteratorUtil32
.materialize(IteratorAggregation32
.bufferedand(IteratorUtil32
.toIterators(x))); | // Path: src/main/java/com/googlecode/javaewah32/EWAHCompressedBitmap32.java
// static int maxSizeInBits(final EWAHCompressedBitmap32... bitmaps) {
// int maxSizeInBits = 0;
// for(EWAHCompressedBitmap32 bitmap : bitmaps) {
// maxSizeInBits = Math.max(maxSizeInBits, bitmap.sizeInBits());
// }
// return maxSizeInBits;
// }
//
// Path: src/test/java/com/googlecode/javaewah/synth/ClusteredDataGenerator.java
// public class ClusteredDataGenerator {
//
// /**
// *
// */
// public ClusteredDataGenerator() {
// this.unidg = new UniformDataGenerator();
// }
//
// /**
// * @param seed random seed
// */
// public ClusteredDataGenerator(final int seed) {
// this.unidg = new UniformDataGenerator(seed);
// }
//
// /**
// * generates randomly N distinct integers from 0 to Max.
// *
// * @param N number of integers
// * @param Max maximum integer value
// * @return a randomly generated array
// */
// public int[] generateClustered(int N, int Max) {
// int[] array = new int[N];
// fillClustered(array, 0, N, 0, Max);
// return array;
// }
//
// void fillClustered(int[] array, int offset, int length, int Min, int Max) {
// final int range = Max - Min;
// if ((range == length) || (length <= 10)) {
// fillUniform(array, offset, length, Min, Max);
// return;
// }
// final int cut = length
// / 2
// + ((range - length - 1 > 0) ? this.unidg.rand
// .nextInt(range - length - 1) : 0);
// final double p = this.unidg.rand.nextDouble();
// if (p < 0.25) {
// fillUniform(array, offset, length / 2, Min, Min + cut);
// fillClustered(array, offset + length / 2, length
// - length / 2, Min + cut, Max);
// } else if (p < 0.5) {
// fillClustered(array, offset, length / 2, Min, Min + cut);
// fillUniform(array, offset + length / 2, length - length
// / 2, Min + cut, Max);
// } else {
// fillClustered(array, offset, length / 2, Min, Min + cut);
// fillClustered(array, offset + length / 2, length
// - length / 2, Min + cut, Max);
// }
// }
//
// void fillUniform(int[] array, int offset, int length, int Min, int Max) {
// int[] v = this.unidg.generateUniform(length, Max - Min);
// for (int k = 0; k < v.length; ++k)
// array[k + offset] = Min + v[k];
// }
//
// private final UniformDataGenerator unidg;
// }
// Path: src/test/java/com/googlecode/javaewah32/IteratorAggregation32Test.java
import static com.googlecode.javaewah32.EWAHCompressedBitmap32.maxSizeInBits;
import static org.junit.Assert.assertTrue;
import java.util.Iterator;
import org.junit.Test;
import com.googlecode.javaewah.synth.ClusteredDataGenerator;
this.sparsity += 3;
return ewah;
}
@Override
public void remove() {
// unimplemented
}
};
}
/**
*
*/
@Test
public void testAnd() {
for (int N = 1; N < 10; ++N) {
System.out.println("testAnd N = " + N);
Iterator<EWAHCompressedBitmap32[]> i = getCollections(
N, 3);
while (i.hasNext()) {
EWAHCompressedBitmap32[] x = i.next();
EWAHCompressedBitmap32 tanswer = EWAHCompressedBitmap32
.and(x);
EWAHCompressedBitmap32 x1 = IteratorUtil32
.materialize(IteratorAggregation32
.bufferedand(IteratorUtil32
.toIterators(x))); | x1.setSizeInBits(maxSizeInBits(x), false); |
lemire/javaewah | src/main/java/com/googlecode/javaewah32/BufferedIterator32.java | // Path: src/main/java/com/googlecode/javaewah/CloneableIterator.java
// public interface CloneableIterator<E> extends Cloneable {
//
// /**
// * @return whether there is more
// */
// boolean hasNext();
//
// /**
// * @return the next element
// */
// E next();
//
// /**
// * @return a copy
// * @throws CloneNotSupportedException this should never happen in practice
// */
// CloneableIterator<E> clone() throws CloneNotSupportedException;
//
// }
| import com.googlecode.javaewah.CloneableIterator; | package com.googlecode.javaewah32;
/*
* Copyright 2009-2016, Daniel Lemire, Cliff Moon, David McIntosh, Robert Becho, Google Inc., Veronika Zenz, Owen Kaser, Gregory Ssi-Yan-Kai, Rory Graves
* Licensed under the Apache License, Version 2.0.
*/
/**
* This class can be used to iterate over blocks of bitmap data.
*
* @author Daniel Lemire
*/
public class BufferedIterator32 implements IteratingRLW32, Cloneable {
/**
* Instantiates a new iterating buffered running length word.
*
* @param iterator iterator
*/
public BufferedIterator32( | // Path: src/main/java/com/googlecode/javaewah/CloneableIterator.java
// public interface CloneableIterator<E> extends Cloneable {
//
// /**
// * @return whether there is more
// */
// boolean hasNext();
//
// /**
// * @return the next element
// */
// E next();
//
// /**
// * @return a copy
// * @throws CloneNotSupportedException this should never happen in practice
// */
// CloneableIterator<E> clone() throws CloneNotSupportedException;
//
// }
// Path: src/main/java/com/googlecode/javaewah32/BufferedIterator32.java
import com.googlecode.javaewah.CloneableIterator;
package com.googlecode.javaewah32;
/*
* Copyright 2009-2016, Daniel Lemire, Cliff Moon, David McIntosh, Robert Becho, Google Inc., Veronika Zenz, Owen Kaser, Gregory Ssi-Yan-Kai, Rory Graves
* Licensed under the Apache License, Version 2.0.
*/
/**
* This class can be used to iterate over blocks of bitmap data.
*
* @author Daniel Lemire
*/
public class BufferedIterator32 implements IteratingRLW32, Cloneable {
/**
* Instantiates a new iterating buffered running length word.
*
* @param iterator iterator
*/
public BufferedIterator32( | final CloneableIterator<EWAHIterator32> iterator) { |
lemire/javaewah | src/test/java/com/googlecode/javaewah32/ThresholdFuncBitmap32Test.java | // Path: src/main/java/com/googlecode/javaewah32/EWAHCompressedBitmap32.java
// static int maxSizeInBits(final EWAHCompressedBitmap32... bitmaps) {
// int maxSizeInBits = 0;
// for(EWAHCompressedBitmap32 bitmap : bitmaps) {
// maxSizeInBits = Math.max(maxSizeInBits, bitmap.sizeInBits());
// }
// return maxSizeInBits;
// }
| import static com.googlecode.javaewah32.EWAHCompressedBitmap32.maxSizeInBits;
import org.junit.Assert;
import org.junit.Test; | .equals(ewah1));
Assert.assertTrue(EWAHCompressedBitmap32.threshold(1, ewah2)
.equals(ewah2));
Assert.assertTrue(EWAHCompressedBitmap32.threshold(1, ewah3)
.equals(ewah3));
Assert.assertTrue(EWAHCompressedBitmap32.threshold(2, ewah1,
ewah1).equals(ewah1));
Assert.assertTrue(EWAHCompressedBitmap32.threshold(2, ewah2,
ewah2).equals(ewah2));
Assert.assertTrue(EWAHCompressedBitmap32.threshold(2, ewah3,
ewah3).equals(ewah3));
EWAHCompressedBitmap32 zero = new EWAHCompressedBitmap32();
Assert.assertTrue(EWAHCompressedBitmap32.threshold(2, ewah1)
.equals(zero));
Assert.assertTrue(EWAHCompressedBitmap32.threshold(2, ewah2)
.equals(zero));
Assert.assertTrue(EWAHCompressedBitmap32.threshold(2, ewah3)
.equals(zero));
Assert.assertTrue(EWAHCompressedBitmap32.threshold(4, ewah1,
ewah2, ewah3).equals(zero));
EWAHCompressedBitmap32 ewahorth = EWAHCompressedBitmap32.threshold(
1, ewah1, ewah2, ewah3);
EWAHCompressedBitmap32 ewahtrueor = EWAHCompressedBitmap32.or(
ewah1, ewah2, ewah3);
Assert.assertTrue(ewahorth.equals(ewahtrueor));
EWAHCompressedBitmap32 ewahandth = EWAHCompressedBitmap32
.threshold(3, ewah1, ewah2, ewah3); | // Path: src/main/java/com/googlecode/javaewah32/EWAHCompressedBitmap32.java
// static int maxSizeInBits(final EWAHCompressedBitmap32... bitmaps) {
// int maxSizeInBits = 0;
// for(EWAHCompressedBitmap32 bitmap : bitmaps) {
// maxSizeInBits = Math.max(maxSizeInBits, bitmap.sizeInBits());
// }
// return maxSizeInBits;
// }
// Path: src/test/java/com/googlecode/javaewah32/ThresholdFuncBitmap32Test.java
import static com.googlecode.javaewah32.EWAHCompressedBitmap32.maxSizeInBits;
import org.junit.Assert;
import org.junit.Test;
.equals(ewah1));
Assert.assertTrue(EWAHCompressedBitmap32.threshold(1, ewah2)
.equals(ewah2));
Assert.assertTrue(EWAHCompressedBitmap32.threshold(1, ewah3)
.equals(ewah3));
Assert.assertTrue(EWAHCompressedBitmap32.threshold(2, ewah1,
ewah1).equals(ewah1));
Assert.assertTrue(EWAHCompressedBitmap32.threshold(2, ewah2,
ewah2).equals(ewah2));
Assert.assertTrue(EWAHCompressedBitmap32.threshold(2, ewah3,
ewah3).equals(ewah3));
EWAHCompressedBitmap32 zero = new EWAHCompressedBitmap32();
Assert.assertTrue(EWAHCompressedBitmap32.threshold(2, ewah1)
.equals(zero));
Assert.assertTrue(EWAHCompressedBitmap32.threshold(2, ewah2)
.equals(zero));
Assert.assertTrue(EWAHCompressedBitmap32.threshold(2, ewah3)
.equals(zero));
Assert.assertTrue(EWAHCompressedBitmap32.threshold(4, ewah1,
ewah2, ewah3).equals(zero));
EWAHCompressedBitmap32 ewahorth = EWAHCompressedBitmap32.threshold(
1, ewah1, ewah2, ewah3);
EWAHCompressedBitmap32 ewahtrueor = EWAHCompressedBitmap32.or(
ewah1, ewah2, ewah3);
Assert.assertTrue(ewahorth.equals(ewahtrueor));
EWAHCompressedBitmap32 ewahandth = EWAHCompressedBitmap32
.threshold(3, ewah1, ewah2, ewah3); | ewahandth.setSizeInBitsWithinLastWord(maxSizeInBits(ewah1, ewah2, ewah3)); |
lemire/javaewah | src/test/java/com/googlecode/javaewah32/IntIteratorOverIteratingRLW32Test.java | // Path: src/main/java/com/googlecode/javaewah/IntIterator.java
// public interface IntIterator {
//
// /**
// * Is there more?
// *
// * @return true, if there is more, false otherwise
// */
// boolean hasNext();
//
// /**
// * Return the next integer
// *
// * @return the integer
// */
// int next();
// }
| import java.util.Iterator;
import org.junit.Test;
import com.googlecode.javaewah.IntIterator;
import static org.junit.Assert.*; | EWAHCompressedBitmap32 e1 = EWAHCompressedBitmap32.bitmapOf(0, 2, 1000, 10001);
EWAHCompressedBitmap32 e2 = new EWAHCompressedBitmap32();
for (int k = 64; k < 450; ++k)
e2.set(k);
EWAHCompressedBitmap32 e3 = new EWAHCompressedBitmap32();
for (int k = 64; k < 450; ++k)
e2.set(400 * k);
assertEquals(IteratorUtil32.materialize(
IteratorAggregation32.bufferedand(e1.getIteratingRLW(), e2.getIteratingRLW(), e3.getIteratingRLW())),
FastAggregation32.bufferedand(1024, e1, e2, e3));
assertEquals(IteratorUtil32.materialize(
IteratorAggregation32.bufferedor(e1.getIteratingRLW(), e2.getIteratingRLW(), e3.getIteratingRLW())),
FastAggregation32.bufferedor(1024, e1, e2, e3));
assertEquals(IteratorUtil32.materialize(
IteratorAggregation32.bufferedxor(e1.getIteratingRLW(), e2.getIteratingRLW(), e3.getIteratingRLW())),
FastAggregation32.bufferedxor(1024, e1, e2, e3));
assertEquals(IteratorUtil32.materialize(IteratorAggregation32.bufferedand(500, e1.getIteratingRLW(),
e2.getIteratingRLW(), e3.getIteratingRLW())), FastAggregation32.bufferedand(1024, e1, e2, e3));
assertEquals(IteratorUtil32.materialize(IteratorAggregation32.bufferedor(500, e1.getIteratingRLW(),
e2.getIteratingRLW(), e3.getIteratingRLW())), FastAggregation32.bufferedor(1024, e1, e2, e3));
assertEquals(IteratorUtil32.materialize(IteratorAggregation32.bufferedxor(500, e1.getIteratingRLW(),
e2.getIteratingRLW(), e3.getIteratingRLW())), FastAggregation32.bufferedxor(1024, e1, e2, e3));
}
@Test
// had problems with bitmaps beginning with two consecutive clean runs
public void testConsecClean() {
System.out.println("testing int iteration, 2 consec clean runs starting with zeros");
EWAHCompressedBitmap32 e = new EWAHCompressedBitmap32();
for (int i = 32; i < 64; ++i)
e.set(i); | // Path: src/main/java/com/googlecode/javaewah/IntIterator.java
// public interface IntIterator {
//
// /**
// * Is there more?
// *
// * @return true, if there is more, false otherwise
// */
// boolean hasNext();
//
// /**
// * Return the next integer
// *
// * @return the integer
// */
// int next();
// }
// Path: src/test/java/com/googlecode/javaewah32/IntIteratorOverIteratingRLW32Test.java
import java.util.Iterator;
import org.junit.Test;
import com.googlecode.javaewah.IntIterator;
import static org.junit.Assert.*;
EWAHCompressedBitmap32 e1 = EWAHCompressedBitmap32.bitmapOf(0, 2, 1000, 10001);
EWAHCompressedBitmap32 e2 = new EWAHCompressedBitmap32();
for (int k = 64; k < 450; ++k)
e2.set(k);
EWAHCompressedBitmap32 e3 = new EWAHCompressedBitmap32();
for (int k = 64; k < 450; ++k)
e2.set(400 * k);
assertEquals(IteratorUtil32.materialize(
IteratorAggregation32.bufferedand(e1.getIteratingRLW(), e2.getIteratingRLW(), e3.getIteratingRLW())),
FastAggregation32.bufferedand(1024, e1, e2, e3));
assertEquals(IteratorUtil32.materialize(
IteratorAggregation32.bufferedor(e1.getIteratingRLW(), e2.getIteratingRLW(), e3.getIteratingRLW())),
FastAggregation32.bufferedor(1024, e1, e2, e3));
assertEquals(IteratorUtil32.materialize(
IteratorAggregation32.bufferedxor(e1.getIteratingRLW(), e2.getIteratingRLW(), e3.getIteratingRLW())),
FastAggregation32.bufferedxor(1024, e1, e2, e3));
assertEquals(IteratorUtil32.materialize(IteratorAggregation32.bufferedand(500, e1.getIteratingRLW(),
e2.getIteratingRLW(), e3.getIteratingRLW())), FastAggregation32.bufferedand(1024, e1, e2, e3));
assertEquals(IteratorUtil32.materialize(IteratorAggregation32.bufferedor(500, e1.getIteratingRLW(),
e2.getIteratingRLW(), e3.getIteratingRLW())), FastAggregation32.bufferedor(1024, e1, e2, e3));
assertEquals(IteratorUtil32.materialize(IteratorAggregation32.bufferedxor(500, e1.getIteratingRLW(),
e2.getIteratingRLW(), e3.getIteratingRLW())), FastAggregation32.bufferedxor(1024, e1, e2, e3));
}
@Test
// had problems with bitmaps beginning with two consecutive clean runs
public void testConsecClean() {
System.out.println("testing int iteration, 2 consec clean runs starting with zeros");
EWAHCompressedBitmap32 e = new EWAHCompressedBitmap32();
for (int i = 32; i < 64; ++i)
e.set(i); | IntIterator ii = IteratorUtil32.toSetBitsIntIterator(e.getIteratingRLW()); |
lemire/javaewah | src/test/java/com/googlecode/javaewah/IteratorAggregationTest.java | // Path: src/main/java/com/googlecode/javaewah/EWAHCompressedBitmap.java
// static int maxSizeInBits(final EWAHCompressedBitmap... bitmaps) {
// int maxSizeInBits = 0;
// for(EWAHCompressedBitmap bitmap : bitmaps) {
// maxSizeInBits = Math.max(maxSizeInBits, bitmap.sizeInBits());
// }
// return maxSizeInBits;
// }
//
// Path: src/test/java/com/googlecode/javaewah/synth/ClusteredDataGenerator.java
// public class ClusteredDataGenerator {
//
// /**
// *
// */
// public ClusteredDataGenerator() {
// this.unidg = new UniformDataGenerator();
// }
//
// /**
// * @param seed random seed
// */
// public ClusteredDataGenerator(final int seed) {
// this.unidg = new UniformDataGenerator(seed);
// }
//
// /**
// * generates randomly N distinct integers from 0 to Max.
// *
// * @param N number of integers
// * @param Max maximum integer value
// * @return a randomly generated array
// */
// public int[] generateClustered(int N, int Max) {
// int[] array = new int[N];
// fillClustered(array, 0, N, 0, Max);
// return array;
// }
//
// void fillClustered(int[] array, int offset, int length, int Min, int Max) {
// final int range = Max - Min;
// if ((range == length) || (length <= 10)) {
// fillUniform(array, offset, length, Min, Max);
// return;
// }
// final int cut = length
// / 2
// + ((range - length - 1 > 0) ? this.unidg.rand
// .nextInt(range - length - 1) : 0);
// final double p = this.unidg.rand.nextDouble();
// if (p < 0.25) {
// fillUniform(array, offset, length / 2, Min, Min + cut);
// fillClustered(array, offset + length / 2, length
// - length / 2, Min + cut, Max);
// } else if (p < 0.5) {
// fillClustered(array, offset, length / 2, Min, Min + cut);
// fillUniform(array, offset + length / 2, length - length
// / 2, Min + cut, Max);
// } else {
// fillClustered(array, offset, length / 2, Min, Min + cut);
// fillClustered(array, offset + length / 2, length
// - length / 2, Min + cut, Max);
// }
// }
//
// void fillUniform(int[] array, int offset, int length, int Min, int Max) {
// int[] v = this.unidg.generateUniform(length, Max - Min);
// for (int k = 0; k < v.length; ++k)
// array[k + offset] = Min + v[k];
// }
//
// private final UniformDataGenerator unidg;
// }
| import static com.googlecode.javaewah.EWAHCompressedBitmap.maxSizeInBits;
import static org.junit.Assert.assertTrue;
import java.util.Iterator;
import org.junit.Test;
import com.googlecode.javaewah.synth.ClusteredDataGenerator; | package com.googlecode.javaewah;
/*
* Copyright 2009-2016, Daniel Lemire, Cliff Moon, David McIntosh, Robert Becho, Google Inc., Veronika Zenz, Owen Kaser, Gregory Ssi-Yan-Kai, Rory Graves
* Licensed under the Apache License, Version 2.0.
*/
/**
* Tests specifically for iterators.
*/
public class IteratorAggregationTest {
/**
* @param N Number of bitmaps to generate in each set
* @param nbr parameter determining the size of the arrays (in a log
* scale)
* @return an iterator over sets of bitmaps
*/
public static Iterator<EWAHCompressedBitmap[]> getCollections(
final int N, final int nbr) { | // Path: src/main/java/com/googlecode/javaewah/EWAHCompressedBitmap.java
// static int maxSizeInBits(final EWAHCompressedBitmap... bitmaps) {
// int maxSizeInBits = 0;
// for(EWAHCompressedBitmap bitmap : bitmaps) {
// maxSizeInBits = Math.max(maxSizeInBits, bitmap.sizeInBits());
// }
// return maxSizeInBits;
// }
//
// Path: src/test/java/com/googlecode/javaewah/synth/ClusteredDataGenerator.java
// public class ClusteredDataGenerator {
//
// /**
// *
// */
// public ClusteredDataGenerator() {
// this.unidg = new UniformDataGenerator();
// }
//
// /**
// * @param seed random seed
// */
// public ClusteredDataGenerator(final int seed) {
// this.unidg = new UniformDataGenerator(seed);
// }
//
// /**
// * generates randomly N distinct integers from 0 to Max.
// *
// * @param N number of integers
// * @param Max maximum integer value
// * @return a randomly generated array
// */
// public int[] generateClustered(int N, int Max) {
// int[] array = new int[N];
// fillClustered(array, 0, N, 0, Max);
// return array;
// }
//
// void fillClustered(int[] array, int offset, int length, int Min, int Max) {
// final int range = Max - Min;
// if ((range == length) || (length <= 10)) {
// fillUniform(array, offset, length, Min, Max);
// return;
// }
// final int cut = length
// / 2
// + ((range - length - 1 > 0) ? this.unidg.rand
// .nextInt(range - length - 1) : 0);
// final double p = this.unidg.rand.nextDouble();
// if (p < 0.25) {
// fillUniform(array, offset, length / 2, Min, Min + cut);
// fillClustered(array, offset + length / 2, length
// - length / 2, Min + cut, Max);
// } else if (p < 0.5) {
// fillClustered(array, offset, length / 2, Min, Min + cut);
// fillUniform(array, offset + length / 2, length - length
// / 2, Min + cut, Max);
// } else {
// fillClustered(array, offset, length / 2, Min, Min + cut);
// fillClustered(array, offset + length / 2, length
// - length / 2, Min + cut, Max);
// }
// }
//
// void fillUniform(int[] array, int offset, int length, int Min, int Max) {
// int[] v = this.unidg.generateUniform(length, Max - Min);
// for (int k = 0; k < v.length; ++k)
// array[k + offset] = Min + v[k];
// }
//
// private final UniformDataGenerator unidg;
// }
// Path: src/test/java/com/googlecode/javaewah/IteratorAggregationTest.java
import static com.googlecode.javaewah.EWAHCompressedBitmap.maxSizeInBits;
import static org.junit.Assert.assertTrue;
import java.util.Iterator;
import org.junit.Test;
import com.googlecode.javaewah.synth.ClusteredDataGenerator;
package com.googlecode.javaewah;
/*
* Copyright 2009-2016, Daniel Lemire, Cliff Moon, David McIntosh, Robert Becho, Google Inc., Veronika Zenz, Owen Kaser, Gregory Ssi-Yan-Kai, Rory Graves
* Licensed under the Apache License, Version 2.0.
*/
/**
* Tests specifically for iterators.
*/
public class IteratorAggregationTest {
/**
* @param N Number of bitmaps to generate in each set
* @param nbr parameter determining the size of the arrays (in a log
* scale)
* @return an iterator over sets of bitmaps
*/
public static Iterator<EWAHCompressedBitmap[]> getCollections(
final int N, final int nbr) { | final ClusteredDataGenerator cdg = new ClusteredDataGenerator(123); |
lemire/javaewah | src/test/java/com/googlecode/javaewah/IteratorAggregationTest.java | // Path: src/main/java/com/googlecode/javaewah/EWAHCompressedBitmap.java
// static int maxSizeInBits(final EWAHCompressedBitmap... bitmaps) {
// int maxSizeInBits = 0;
// for(EWAHCompressedBitmap bitmap : bitmaps) {
// maxSizeInBits = Math.max(maxSizeInBits, bitmap.sizeInBits());
// }
// return maxSizeInBits;
// }
//
// Path: src/test/java/com/googlecode/javaewah/synth/ClusteredDataGenerator.java
// public class ClusteredDataGenerator {
//
// /**
// *
// */
// public ClusteredDataGenerator() {
// this.unidg = new UniformDataGenerator();
// }
//
// /**
// * @param seed random seed
// */
// public ClusteredDataGenerator(final int seed) {
// this.unidg = new UniformDataGenerator(seed);
// }
//
// /**
// * generates randomly N distinct integers from 0 to Max.
// *
// * @param N number of integers
// * @param Max maximum integer value
// * @return a randomly generated array
// */
// public int[] generateClustered(int N, int Max) {
// int[] array = new int[N];
// fillClustered(array, 0, N, 0, Max);
// return array;
// }
//
// void fillClustered(int[] array, int offset, int length, int Min, int Max) {
// final int range = Max - Min;
// if ((range == length) || (length <= 10)) {
// fillUniform(array, offset, length, Min, Max);
// return;
// }
// final int cut = length
// / 2
// + ((range - length - 1 > 0) ? this.unidg.rand
// .nextInt(range - length - 1) : 0);
// final double p = this.unidg.rand.nextDouble();
// if (p < 0.25) {
// fillUniform(array, offset, length / 2, Min, Min + cut);
// fillClustered(array, offset + length / 2, length
// - length / 2, Min + cut, Max);
// } else if (p < 0.5) {
// fillClustered(array, offset, length / 2, Min, Min + cut);
// fillUniform(array, offset + length / 2, length - length
// / 2, Min + cut, Max);
// } else {
// fillClustered(array, offset, length / 2, Min, Min + cut);
// fillClustered(array, offset + length / 2, length
// - length / 2, Min + cut, Max);
// }
// }
//
// void fillUniform(int[] array, int offset, int length, int Min, int Max) {
// int[] v = this.unidg.generateUniform(length, Max - Min);
// for (int k = 0; k < v.length; ++k)
// array[k + offset] = Min + v[k];
// }
//
// private final UniformDataGenerator unidg;
// }
| import static com.googlecode.javaewah.EWAHCompressedBitmap.maxSizeInBits;
import static org.junit.Assert.assertTrue;
import java.util.Iterator;
import org.junit.Test;
import com.googlecode.javaewah.synth.ClusteredDataGenerator; | }
this.sparsity += 3;
return ewah;
}
@Override
public void remove() {
// unimplemented
}
};
}
/**
*
*/
@Test
public void testAnd() {
for (int N = 1; N < 10; ++N) {
System.out.println("testAnd N = " + N);
Iterator<EWAHCompressedBitmap[]> i = getCollections(N,
3);
while (i.hasNext()) {
EWAHCompressedBitmap[] x = i.next();
EWAHCompressedBitmap tanswer = EWAHCompressedBitmap.and(x);
EWAHCompressedBitmap x1 = IteratorUtil
.materialize(IteratorAggregation
.bufferedand(IteratorUtil
.toIterators(x))); | // Path: src/main/java/com/googlecode/javaewah/EWAHCompressedBitmap.java
// static int maxSizeInBits(final EWAHCompressedBitmap... bitmaps) {
// int maxSizeInBits = 0;
// for(EWAHCompressedBitmap bitmap : bitmaps) {
// maxSizeInBits = Math.max(maxSizeInBits, bitmap.sizeInBits());
// }
// return maxSizeInBits;
// }
//
// Path: src/test/java/com/googlecode/javaewah/synth/ClusteredDataGenerator.java
// public class ClusteredDataGenerator {
//
// /**
// *
// */
// public ClusteredDataGenerator() {
// this.unidg = new UniformDataGenerator();
// }
//
// /**
// * @param seed random seed
// */
// public ClusteredDataGenerator(final int seed) {
// this.unidg = new UniformDataGenerator(seed);
// }
//
// /**
// * generates randomly N distinct integers from 0 to Max.
// *
// * @param N number of integers
// * @param Max maximum integer value
// * @return a randomly generated array
// */
// public int[] generateClustered(int N, int Max) {
// int[] array = new int[N];
// fillClustered(array, 0, N, 0, Max);
// return array;
// }
//
// void fillClustered(int[] array, int offset, int length, int Min, int Max) {
// final int range = Max - Min;
// if ((range == length) || (length <= 10)) {
// fillUniform(array, offset, length, Min, Max);
// return;
// }
// final int cut = length
// / 2
// + ((range - length - 1 > 0) ? this.unidg.rand
// .nextInt(range - length - 1) : 0);
// final double p = this.unidg.rand.nextDouble();
// if (p < 0.25) {
// fillUniform(array, offset, length / 2, Min, Min + cut);
// fillClustered(array, offset + length / 2, length
// - length / 2, Min + cut, Max);
// } else if (p < 0.5) {
// fillClustered(array, offset, length / 2, Min, Min + cut);
// fillUniform(array, offset + length / 2, length - length
// / 2, Min + cut, Max);
// } else {
// fillClustered(array, offset, length / 2, Min, Min + cut);
// fillClustered(array, offset + length / 2, length
// - length / 2, Min + cut, Max);
// }
// }
//
// void fillUniform(int[] array, int offset, int length, int Min, int Max) {
// int[] v = this.unidg.generateUniform(length, Max - Min);
// for (int k = 0; k < v.length; ++k)
// array[k + offset] = Min + v[k];
// }
//
// private final UniformDataGenerator unidg;
// }
// Path: src/test/java/com/googlecode/javaewah/IteratorAggregationTest.java
import static com.googlecode.javaewah.EWAHCompressedBitmap.maxSizeInBits;
import static org.junit.Assert.assertTrue;
import java.util.Iterator;
import org.junit.Test;
import com.googlecode.javaewah.synth.ClusteredDataGenerator;
}
this.sparsity += 3;
return ewah;
}
@Override
public void remove() {
// unimplemented
}
};
}
/**
*
*/
@Test
public void testAnd() {
for (int N = 1; N < 10; ++N) {
System.out.println("testAnd N = " + N);
Iterator<EWAHCompressedBitmap[]> i = getCollections(N,
3);
while (i.hasNext()) {
EWAHCompressedBitmap[] x = i.next();
EWAHCompressedBitmap tanswer = EWAHCompressedBitmap.and(x);
EWAHCompressedBitmap x1 = IteratorUtil
.materialize(IteratorAggregation
.bufferedand(IteratorUtil
.toIterators(x))); | x1.setSizeInBits(maxSizeInBits(x), false); |
lemire/javaewah | src/main/java/com/googlecode/javaewah/ClearIntIterator.java | // Path: src/main/java/com/googlecode/javaewah/EWAHCompressedBitmap.java
// public static final int WORD_IN_BITS = 64;
| import static com.googlecode.javaewah.EWAHCompressedBitmap.WORD_IN_BITS; | while (!runningHasNext() && !literalHasNext()) {
if (!this.ewahIter.hasNext()) {
return false;
}
setRunningLengthWord(this.ewahIter.next());
}
return true;
}
@Override
public boolean hasNext() {
return this.hasNext;
}
@Override
public int next() {
final int answer;
if (runningHasNext()) {
answer = this.position++;
} else {
final long t = this.word & -this.word;
answer = this.literalPosition + Long.bitCount(t - 1);
this.word ^= t;
}
this.hasNext = this.moveToNext();
return answer;
}
private void setRunningLengthWord(RunningLengthWord rlw) {
this.runningLength = Math.min(this.sizeInBits, | // Path: src/main/java/com/googlecode/javaewah/EWAHCompressedBitmap.java
// public static final int WORD_IN_BITS = 64;
// Path: src/main/java/com/googlecode/javaewah/ClearIntIterator.java
import static com.googlecode.javaewah.EWAHCompressedBitmap.WORD_IN_BITS;
while (!runningHasNext() && !literalHasNext()) {
if (!this.ewahIter.hasNext()) {
return false;
}
setRunningLengthWord(this.ewahIter.next());
}
return true;
}
@Override
public boolean hasNext() {
return this.hasNext;
}
@Override
public int next() {
final int answer;
if (runningHasNext()) {
answer = this.position++;
} else {
final long t = this.word & -this.word;
answer = this.literalPosition + Long.bitCount(t - 1);
this.word ^= t;
}
this.hasNext = this.moveToNext();
return answer;
}
private void setRunningLengthWord(RunningLengthWord rlw) {
this.runningLength = Math.min(this.sizeInBits, | WORD_IN_BITS * (int) rlw.getRunningLength() + this.position); |
lemire/javaewah | src/main/java/com/googlecode/javaewah/symmetric/ThresholdFuncBitmap.java | // Path: src/main/java/com/googlecode/javaewah/BitmapStorage.java
// public interface BitmapStorage {
//
// /**
// * Adding words directly to the bitmap (for expert use).
// *
// * This is normally how you add data to the array. So you add bits in
// * streams of 8*8 bits.
// *
// * @param newData the word
// */
// void addWord(final long newData);
//
// /**
// * Adding literal words directly to the bitmap (for expert use).
// *
// * @param newData the word
// */
// void addLiteralWord(final long newData);
//
// /**
// * if you have several literal words to copy over, this might be faster.
// *
// * @param buffer the buffer wrapping the literal words
// * @param start the starting point in the array
// * @param number the number of literal words to add
// */
// void addStreamOfLiteralWords(final Buffer buffer, final int start, final int number);
//
// /**
// * For experts: You want to add many zeroes or ones? This is the method
// * you use.
// *
// * @param v zeros or ones
// * @param number how many to words add
// */
// void addStreamOfEmptyWords(final boolean v, final long number);
//
// /**
// * Like "addStreamOfLiteralWords" but negates the words being added.
// *
// * @param buffer the buffer wrapping the literal words
// * @param start the starting point in the array
// * @param number the number of literal words to add
// */
// void addStreamOfNegatedLiteralWords(final Buffer buffer, final int start, final int number);
//
// /**
// * Empties the container.
// */
// void clear();
//
// /**
// * Sets the size in bits of the bitmap as an *uncompressed* bitmap.
// * Normally, this is used to reduce the size of the bitmaps within
// * the scope of the last word. Specifically, this means that
// * (sizeInBits()+63)/64 must be equal to (size +63)/64.
// * If needed, the bitmap can be further padded with zeroes.
// *
// * @param size the size in bits
// */
// void setSizeInBitsWithinLastWord(final int size);
// }
| import com.googlecode.javaewah.BitmapStorage;
import java.util.Arrays; | package com.googlecode.javaewah.symmetric;
/**
* A threshold Boolean function returns true if the number of true values exceed
* a threshold. It is a symmetric Boolean function.
*
* This class implements an algorithm described in the following paper:
*
* Owen Kaser and Daniel Lemire, Compressed bitmap indexes: beyond unions and intersections
* <a href="http://arxiv.org/abs/1402.4466">http://arxiv.org/abs/1402.4466</a>
*
* It is not thread safe: you should use one object per thread.
*
* @author Daniel Lemire
* @see <a
* href="http://en.wikipedia.org/wiki/Symmetric_Boolean_function">http://en.wikipedia.org/wiki/Symmetric_Boolean_function</a>
* @since 0.8.0
*/
public final class ThresholdFuncBitmap extends UpdateableBitmapFunction {
private final int min;
private long[] buffers;
private int bufferUsed;
private final int[] bufCounters = new int[64];
private static final int[] zeroes64 = new int[64];
/**
* Construction a threshold function with a given threshold
*
* @param min threshold
*/
public ThresholdFuncBitmap(final int min) {
super();
this.min = min;
this.buffers = new long[16];
this.bufferUsed = 0;
}
@Override | // Path: src/main/java/com/googlecode/javaewah/BitmapStorage.java
// public interface BitmapStorage {
//
// /**
// * Adding words directly to the bitmap (for expert use).
// *
// * This is normally how you add data to the array. So you add bits in
// * streams of 8*8 bits.
// *
// * @param newData the word
// */
// void addWord(final long newData);
//
// /**
// * Adding literal words directly to the bitmap (for expert use).
// *
// * @param newData the word
// */
// void addLiteralWord(final long newData);
//
// /**
// * if you have several literal words to copy over, this might be faster.
// *
// * @param buffer the buffer wrapping the literal words
// * @param start the starting point in the array
// * @param number the number of literal words to add
// */
// void addStreamOfLiteralWords(final Buffer buffer, final int start, final int number);
//
// /**
// * For experts: You want to add many zeroes or ones? This is the method
// * you use.
// *
// * @param v zeros or ones
// * @param number how many to words add
// */
// void addStreamOfEmptyWords(final boolean v, final long number);
//
// /**
// * Like "addStreamOfLiteralWords" but negates the words being added.
// *
// * @param buffer the buffer wrapping the literal words
// * @param start the starting point in the array
// * @param number the number of literal words to add
// */
// void addStreamOfNegatedLiteralWords(final Buffer buffer, final int start, final int number);
//
// /**
// * Empties the container.
// */
// void clear();
//
// /**
// * Sets the size in bits of the bitmap as an *uncompressed* bitmap.
// * Normally, this is used to reduce the size of the bitmaps within
// * the scope of the last word. Specifically, this means that
// * (sizeInBits()+63)/64 must be equal to (size +63)/64.
// * If needed, the bitmap can be further padded with zeroes.
// *
// * @param size the size in bits
// */
// void setSizeInBitsWithinLastWord(final int size);
// }
// Path: src/main/java/com/googlecode/javaewah/symmetric/ThresholdFuncBitmap.java
import com.googlecode.javaewah.BitmapStorage;
import java.util.Arrays;
package com.googlecode.javaewah.symmetric;
/**
* A threshold Boolean function returns true if the number of true values exceed
* a threshold. It is a symmetric Boolean function.
*
* This class implements an algorithm described in the following paper:
*
* Owen Kaser and Daniel Lemire, Compressed bitmap indexes: beyond unions and intersections
* <a href="http://arxiv.org/abs/1402.4466">http://arxiv.org/abs/1402.4466</a>
*
* It is not thread safe: you should use one object per thread.
*
* @author Daniel Lemire
* @see <a
* href="http://en.wikipedia.org/wiki/Symmetric_Boolean_function">http://en.wikipedia.org/wiki/Symmetric_Boolean_function</a>
* @since 0.8.0
*/
public final class ThresholdFuncBitmap extends UpdateableBitmapFunction {
private final int min;
private long[] buffers;
private int bufferUsed;
private final int[] bufCounters = new int[64];
private static final int[] zeroes64 = new int[64];
/**
* Construction a threshold function with a given threshold
*
* @param min threshold
*/
public ThresholdFuncBitmap(final int min) {
super();
this.min = min;
this.buffers = new long[16];
this.bufferUsed = 0;
}
@Override | public void dispatch(BitmapStorage out, int runBegin, int runEnd) { |
lemire/javaewah | src/main/java/com/googlecode/javaewah/datastructure/ImmutableBitSet.java | // Path: src/main/java/com/googlecode/javaewah/IntIterator.java
// public interface IntIterator {
//
// /**
// * Is there more?
// *
// * @return true, if there is more, false otherwise
// */
// boolean hasNext();
//
// /**
// * Return the next integer
// *
// * @return the integer
// */
// int next();
// }
| import java.nio.LongBuffer;
import java.util.Iterator;
import com.googlecode.javaewah.IntIterator; | return true;
}
/**
* get value of bit i
*
* @param i index
* @return value of the bit
*/
public boolean get(final int i) {
return (this.data.get(i / 64) & (1l << (i % 64))) != 0;
}
@Override
public int hashCode() {
int b = 31;
long hash = 0;
int length = this.data.limit();
for(int k = 0; k < length; ++k) {
long aData = this.data.get(k);
hash = hash * b + aData;
}
return (int) hash;
}
/**
* Iterate over the set bits
*
* @return an iterator
*/ | // Path: src/main/java/com/googlecode/javaewah/IntIterator.java
// public interface IntIterator {
//
// /**
// * Is there more?
// *
// * @return true, if there is more, false otherwise
// */
// boolean hasNext();
//
// /**
// * Return the next integer
// *
// * @return the integer
// */
// int next();
// }
// Path: src/main/java/com/googlecode/javaewah/datastructure/ImmutableBitSet.java
import java.nio.LongBuffer;
import java.util.Iterator;
import com.googlecode.javaewah.IntIterator;
return true;
}
/**
* get value of bit i
*
* @param i index
* @return value of the bit
*/
public boolean get(final int i) {
return (this.data.get(i / 64) & (1l << (i % 64))) != 0;
}
@Override
public int hashCode() {
int b = 31;
long hash = 0;
int length = this.data.limit();
for(int k = 0; k < length; ++k) {
long aData = this.data.get(k);
hash = hash * b + aData;
}
return (int) hash;
}
/**
* Iterate over the set bits
*
* @return an iterator
*/ | public IntIterator intIterator() { |
lemire/javaewah | src/main/java/com/googlecode/javaewah/IntIteratorImpl.java | // Path: src/main/java/com/googlecode/javaewah/EWAHCompressedBitmap.java
// public static final int WORD_IN_BITS = 64;
| import static com.googlecode.javaewah.EWAHCompressedBitmap.WORD_IN_BITS; | public boolean moveToNext() {
while (!runningHasNext() && !literalHasNext()) {
if (!this.ewahIter.hasNext()) {
return false;
}
setRunningLengthWord(this.ewahIter.next());
}
return true;
}
@Override
public boolean hasNext() {
return this.hasNext;
}
@Override
public int next() {
final int answer;
if (runningHasNext()) {
answer = this.position++;
} else {
final long t = this.word & -this.word;
answer = this.literalPosition + Long.bitCount(t - 1);
this.word ^= t;
}
this.hasNext = this.moveToNext();
return answer;
}
private void setRunningLengthWord(RunningLengthWord rlw) { | // Path: src/main/java/com/googlecode/javaewah/EWAHCompressedBitmap.java
// public static final int WORD_IN_BITS = 64;
// Path: src/main/java/com/googlecode/javaewah/IntIteratorImpl.java
import static com.googlecode.javaewah.EWAHCompressedBitmap.WORD_IN_BITS;
public boolean moveToNext() {
while (!runningHasNext() && !literalHasNext()) {
if (!this.ewahIter.hasNext()) {
return false;
}
setRunningLengthWord(this.ewahIter.next());
}
return true;
}
@Override
public boolean hasNext() {
return this.hasNext;
}
@Override
public int next() {
final int answer;
if (runningHasNext()) {
answer = this.position++;
} else {
final long t = this.word & -this.word;
answer = this.literalPosition + Long.bitCount(t - 1);
this.word ^= t;
}
this.hasNext = this.moveToNext();
return answer;
}
private void setRunningLengthWord(RunningLengthWord rlw) { | this.runningLength = WORD_IN_BITS * (int) rlw.getRunningLength() + this.position; |
lemire/javaewah | src/main/java/com/googlecode/javaewah32/ChunkIteratorImpl32.java | // Path: src/main/java/com/googlecode/javaewah/ChunkIterator.java
// public interface ChunkIterator {
//
// /**
// * Is there more?
// *
// * @return true, if there is more, false otherwise
// */
// boolean hasNext();
//
// /**
// * Return the next bit
// *
// * @return the bit
// */
// boolean nextBit();
//
// /**
// * Return the length of the next bit
// *
// * @return the length
// */
// int nextLength();
//
// /**
// * Move the iterator at the next different bit
// */
// void move();
//
// /**
// * Move the iterator at the next ith bit
// *
// * @param bits the number of bits to skip
// */
// void move(int bits);
//
// }
//
// Path: src/main/java/com/googlecode/javaewah32/EWAHCompressedBitmap32.java
// public static final int WORD_IN_BITS = 32;
| import static com.googlecode.javaewah32.EWAHCompressedBitmap32.WORD_IN_BITS;
import com.googlecode.javaewah.ChunkIterator; | @Override
public void move() {
move(this.nextLength);
}
@Override
public void move(int bits) {
this.nextLength -= bits;
if(this.nextLength <= 0) {
do {
this.nextBit = null;
updateNext();
this.hasNext = moveToNextRLW();
} while(this.nextLength <= 0 && this.hasNext);
}
}
private boolean moveToNextRLW() {
while (!runningHasNext() && !literalHasNext()) {
if (!hasNextRLW()) {
return this.nextBit!=null;
}
setRLW(nextRLW());
updateNext();
}
return true;
}
private void setRLW(RunningLengthWord32 rlw) {
this.runningLength = Math.min(this.sizeInBits, | // Path: src/main/java/com/googlecode/javaewah/ChunkIterator.java
// public interface ChunkIterator {
//
// /**
// * Is there more?
// *
// * @return true, if there is more, false otherwise
// */
// boolean hasNext();
//
// /**
// * Return the next bit
// *
// * @return the bit
// */
// boolean nextBit();
//
// /**
// * Return the length of the next bit
// *
// * @return the length
// */
// int nextLength();
//
// /**
// * Move the iterator at the next different bit
// */
// void move();
//
// /**
// * Move the iterator at the next ith bit
// *
// * @param bits the number of bits to skip
// */
// void move(int bits);
//
// }
//
// Path: src/main/java/com/googlecode/javaewah32/EWAHCompressedBitmap32.java
// public static final int WORD_IN_BITS = 32;
// Path: src/main/java/com/googlecode/javaewah32/ChunkIteratorImpl32.java
import static com.googlecode.javaewah32.EWAHCompressedBitmap32.WORD_IN_BITS;
import com.googlecode.javaewah.ChunkIterator;
@Override
public void move() {
move(this.nextLength);
}
@Override
public void move(int bits) {
this.nextLength -= bits;
if(this.nextLength <= 0) {
do {
this.nextBit = null;
updateNext();
this.hasNext = moveToNextRLW();
} while(this.nextLength <= 0 && this.hasNext);
}
}
private boolean moveToNextRLW() {
while (!runningHasNext() && !literalHasNext()) {
if (!hasNextRLW()) {
return this.nextBit!=null;
}
setRLW(nextRLW());
updateNext();
}
return true;
}
private void setRLW(RunningLengthWord32 rlw) {
this.runningLength = Math.min(this.sizeInBits, | this.position + WORD_IN_BITS * rlw.getRunningLength()); |
lemire/javaewah | src/main/java/com/googlecode/javaewah/datastructure/BitSet.java | // Path: src/main/java/com/googlecode/javaewah/IntIterator.java
// public interface IntIterator {
//
// /**
// * Is there more?
// *
// * @return true, if there is more, false otherwise
// */
// boolean hasNext();
//
// /**
// * Return the next integer
// *
// * @return the integer
// */
// int next();
// }
| import com.googlecode.javaewah.IntIterator;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.util.Arrays;
import java.util.Iterator; | this.data[i] = ~this.data[i];
this.data[endword] ^= ~0L >>> -end;
}
/**
* Get the value of the bit. This might throw an exception if size() is insufficient, consider calling resize().
* @param i index
* @return value of the bit
*/
public boolean get(final int i) {
return (this.data[i / 64] & (1l << (i % 64))) != 0;
}
@Override
public int hashCode() {
int b = 31;
long hash = 0;
for(int k = 0; k < data.length; ++k) {
long aData = this.getWord(k);
hash = hash * b + aData;
}
return (int) hash;
}
/**
* Iterate over the set bits
*
* @return an iterator
*/ | // Path: src/main/java/com/googlecode/javaewah/IntIterator.java
// public interface IntIterator {
//
// /**
// * Is there more?
// *
// * @return true, if there is more, false otherwise
// */
// boolean hasNext();
//
// /**
// * Return the next integer
// *
// * @return the integer
// */
// int next();
// }
// Path: src/main/java/com/googlecode/javaewah/datastructure/BitSet.java
import com.googlecode.javaewah.IntIterator;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.util.Arrays;
import java.util.Iterator;
this.data[i] = ~this.data[i];
this.data[endword] ^= ~0L >>> -end;
}
/**
* Get the value of the bit. This might throw an exception if size() is insufficient, consider calling resize().
* @param i index
* @return value of the bit
*/
public boolean get(final int i) {
return (this.data[i / 64] & (1l << (i % 64))) != 0;
}
@Override
public int hashCode() {
int b = 31;
long hash = 0;
for(int k = 0; k < data.length; ++k) {
long aData = this.getWord(k);
hash = hash * b + aData;
}
return (int) hash;
}
/**
* Iterate over the set bits
*
* @return an iterator
*/ | public IntIterator intIterator() { |
lemire/javaewah | src/main/java/com/googlecode/javaewah/ChunkIteratorImpl.java | // Path: src/main/java/com/googlecode/javaewah/EWAHCompressedBitmap.java
// public static final int WORD_IN_BITS = 64;
| import static com.googlecode.javaewah.EWAHCompressedBitmap.WORD_IN_BITS; | @Override
public void move() {
move(this.nextLength);
}
@Override
public void move(int bits) {
this.nextLength -= bits;
if(this.nextLength <= 0) {
do {
this.nextBit = null;
updateNext();
this.hasNext = moveToNextRLW();
} while(this.nextLength <= 0 && this.hasNext);
}
}
private boolean moveToNextRLW() {
while (!runningHasNext() && !literalHasNext()) {
if (!hasNextRLW()) {
return this.nextBit!=null;
}
setRLW(nextRLW());
updateNext();
}
return true;
}
private void setRLW(RunningLengthWord rlw) {
this.runningLength = Math.min(this.sizeInBits, | // Path: src/main/java/com/googlecode/javaewah/EWAHCompressedBitmap.java
// public static final int WORD_IN_BITS = 64;
// Path: src/main/java/com/googlecode/javaewah/ChunkIteratorImpl.java
import static com.googlecode.javaewah.EWAHCompressedBitmap.WORD_IN_BITS;
@Override
public void move() {
move(this.nextLength);
}
@Override
public void move(int bits) {
this.nextLength -= bits;
if(this.nextLength <= 0) {
do {
this.nextBit = null;
updateNext();
this.hasNext = moveToNextRLW();
} while(this.nextLength <= 0 && this.hasNext);
}
}
private boolean moveToNextRLW() {
while (!runningHasNext() && !literalHasNext()) {
if (!hasNextRLW()) {
return this.nextBit!=null;
}
setRLW(nextRLW());
updateNext();
}
return true;
}
private void setRLW(RunningLengthWord rlw) {
this.runningLength = Math.min(this.sizeInBits, | this.position + WORD_IN_BITS * (int) rlw.getRunningLength()); |
lemire/javaewah | src/main/java/com/googlecode/javaewah32/IntIteratorOverIteratingRLW32.java | // Path: src/main/java/com/googlecode/javaewah/IntIterator.java
// public interface IntIterator {
//
// /**
// * Is there more?
// *
// * @return true, if there is more, false otherwise
// */
// boolean hasNext();
//
// /**
// * Return the next integer
// *
// * @return the integer
// */
// int next();
// }
//
// Path: src/main/java/com/googlecode/javaewah32/EWAHCompressedBitmap32.java
// public static final int WORD_IN_BITS = 32;
| import com.googlecode.javaewah.IntIterator;
import static com.googlecode.javaewah32.EWAHCompressedBitmap32.WORD_IN_BITS; | private boolean moveToNext() {
while (!runningHasNext() && !literalHasNext()) {
if (this.parent.next())
setupForCurrentRunningLengthWord();
else
return false;
}
return true;
}
@Override
public boolean hasNext() {
return this.hasNext;
}
@Override
public final int next() {
final int answer;
if (runningHasNext()) {
answer = this.position++;
} else {
final int t = this.word & -this.word;
answer = this.literalPosition + Integer.bitCount(t - 1);
this.word ^= t;
}
this.hasNext = this.moveToNext();
return answer;
}
private void setupForCurrentRunningLengthWord() { | // Path: src/main/java/com/googlecode/javaewah/IntIterator.java
// public interface IntIterator {
//
// /**
// * Is there more?
// *
// * @return true, if there is more, false otherwise
// */
// boolean hasNext();
//
// /**
// * Return the next integer
// *
// * @return the integer
// */
// int next();
// }
//
// Path: src/main/java/com/googlecode/javaewah32/EWAHCompressedBitmap32.java
// public static final int WORD_IN_BITS = 32;
// Path: src/main/java/com/googlecode/javaewah32/IntIteratorOverIteratingRLW32.java
import com.googlecode.javaewah.IntIterator;
import static com.googlecode.javaewah32.EWAHCompressedBitmap32.WORD_IN_BITS;
private boolean moveToNext() {
while (!runningHasNext() && !literalHasNext()) {
if (this.parent.next())
setupForCurrentRunningLengthWord();
else
return false;
}
return true;
}
@Override
public boolean hasNext() {
return this.hasNext;
}
@Override
public final int next() {
final int answer;
if (runningHasNext()) {
answer = this.position++;
} else {
final int t = this.word & -this.word;
answer = this.literalPosition + Integer.bitCount(t - 1);
this.word ^= t;
}
this.hasNext = this.moveToNext();
return answer;
}
private void setupForCurrentRunningLengthWord() { | this.runningLength = WORD_IN_BITS |
lemire/javaewah | src/main/java/com/googlecode/javaewah/ReverseIntIterator.java | // Path: src/main/java/com/googlecode/javaewah/EWAHCompressedBitmap.java
// public static final int WORD_IN_BITS = 64;
| import static com.googlecode.javaewah.EWAHCompressedBitmap.WORD_IN_BITS; | }
@Override
public int next() {
final int answer;
if (literalHasNext()) {
final long t = this.word & -this.word;
answer = this.literalPosition - Long.bitCount(t - 1);
this.word ^= t;
} else {
answer = this.position--;
}
this.hasNext = this.moveToPreviousRLW();
return answer;
}
private boolean moveToPreviousRLW() {
while (!literalHasNext() && !runningHasNext()) {
if (!this.ewahIter.hasPrevious()) {
return false;
}
setRLW(this.ewahIter.previous());
}
return true;
}
private void setRLW(RunningLengthWord rlw) {
this.wordLength = rlw.getNumberOfLiteralWords();
this.wordPosition = this.ewahIter.position();
this.position = this.runningLength; | // Path: src/main/java/com/googlecode/javaewah/EWAHCompressedBitmap.java
// public static final int WORD_IN_BITS = 64;
// Path: src/main/java/com/googlecode/javaewah/ReverseIntIterator.java
import static com.googlecode.javaewah.EWAHCompressedBitmap.WORD_IN_BITS;
}
@Override
public int next() {
final int answer;
if (literalHasNext()) {
final long t = this.word & -this.word;
answer = this.literalPosition - Long.bitCount(t - 1);
this.word ^= t;
} else {
answer = this.position--;
}
this.hasNext = this.moveToPreviousRLW();
return answer;
}
private boolean moveToPreviousRLW() {
while (!literalHasNext() && !runningHasNext()) {
if (!this.ewahIter.hasPrevious()) {
return false;
}
setRLW(this.ewahIter.previous());
}
return true;
}
private void setRLW(RunningLengthWord rlw) {
this.wordLength = rlw.getNumberOfLiteralWords();
this.wordPosition = this.ewahIter.position();
this.position = this.runningLength; | this.runningLength -= WORD_IN_BITS * (rlw.getRunningLength() + this.wordLength); |
lemire/javaewah | src/test/java/com/googlecode/javaewah/datastructure/BitSetTest.java | // Path: src/main/java/com/googlecode/javaewah/IntIterator.java
// public interface IntIterator {
//
// /**
// * Is there more?
// *
// * @return true, if there is more, false otherwise
// */
// boolean hasNext();
//
// /**
// * Return the next integer
// *
// * @return the integer
// */
// int next();
// }
| import static org.junit.Assert.*;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import junit.framework.Assert;
import org.junit.Test;
import com.googlecode.javaewah.IntIterator; | package com.googlecode.javaewah.datastructure;
public class BitSetTest
{
public static ImmutableBitSet toImmutableBitSet(BitSet b) throws IOException {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
b.serialize(new DataOutputStream(bos));
ByteBuffer bb = ByteBuffer.wrap(bos.toByteArray());
ImmutableBitSet rmap = new ImmutableBitSet(bb.asLongBuffer());
System.out.println("bitmap 1 (mapped) : " + rmap);
if (!rmap.equals(b))
throw new RuntimeException("Will not happen");
return rmap;
}
@Test
public void simpleImmuExample() throws IOException {
ImmutableBitSet Bitmap1 = toImmutableBitSet(BitSet.bitmapOf(0, 2, 55, 64, 512));
ImmutableBitSet Bitmap2 = toImmutableBitSet(BitSet.bitmapOf(1, 3, 64, 512));
System.out.println("bitmap 1: " + Bitmap1);
System.out.println("bitmap 2: " + Bitmap2);
assertEquals(Bitmap1.cardinality(),5);
assertEquals(Bitmap2.cardinality(),4);
assertFalse(Bitmap1.hashCode()==Bitmap2.hashCode()); | // Path: src/main/java/com/googlecode/javaewah/IntIterator.java
// public interface IntIterator {
//
// /**
// * Is there more?
// *
// * @return true, if there is more, false otherwise
// */
// boolean hasNext();
//
// /**
// * Return the next integer
// *
// * @return the integer
// */
// int next();
// }
// Path: src/test/java/com/googlecode/javaewah/datastructure/BitSetTest.java
import static org.junit.Assert.*;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import junit.framework.Assert;
import org.junit.Test;
import com.googlecode.javaewah.IntIterator;
package com.googlecode.javaewah.datastructure;
public class BitSetTest
{
public static ImmutableBitSet toImmutableBitSet(BitSet b) throws IOException {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
b.serialize(new DataOutputStream(bos));
ByteBuffer bb = ByteBuffer.wrap(bos.toByteArray());
ImmutableBitSet rmap = new ImmutableBitSet(bb.asLongBuffer());
System.out.println("bitmap 1 (mapped) : " + rmap);
if (!rmap.equals(b))
throw new RuntimeException("Will not happen");
return rmap;
}
@Test
public void simpleImmuExample() throws IOException {
ImmutableBitSet Bitmap1 = toImmutableBitSet(BitSet.bitmapOf(0, 2, 55, 64, 512));
ImmutableBitSet Bitmap2 = toImmutableBitSet(BitSet.bitmapOf(1, 3, 64, 512));
System.out.println("bitmap 1: " + Bitmap1);
System.out.println("bitmap 2: " + Bitmap2);
assertEquals(Bitmap1.cardinality(),5);
assertEquals(Bitmap2.cardinality(),4);
assertFalse(Bitmap1.hashCode()==Bitmap2.hashCode()); | IntIterator is = Bitmap1.intIterator(); |
lemire/javaewah | src/test/java/com/googlecode/javaewah/ThresholdFuncBitmapTest.java | // Path: src/main/java/com/googlecode/javaewah/EWAHCompressedBitmap.java
// static int maxSizeInBits(final EWAHCompressedBitmap... bitmaps) {
// int maxSizeInBits = 0;
// for(EWAHCompressedBitmap bitmap : bitmaps) {
// maxSizeInBits = Math.max(maxSizeInBits, bitmap.sizeInBits());
// }
// return maxSizeInBits;
// }
| import static com.googlecode.javaewah.EWAHCompressedBitmap.maxSizeInBits;
import org.junit.Assert;
import org.junit.Test; | EWAHCompressedBitmap ewah3 = EWAHCompressedBitmap.bitmapOf(1,
110, 1000, 1101, 1200, 1201, 31416, 31417);
Assert.assertTrue(EWAHCompressedBitmap.threshold(1, ewah1)
.equals(ewah1));
Assert.assertTrue(EWAHCompressedBitmap.threshold(1, ewah2)
.equals(ewah2));
Assert.assertTrue(EWAHCompressedBitmap.threshold(1, ewah3)
.equals(ewah3));
Assert.assertTrue(EWAHCompressedBitmap.threshold(2, ewah1,
ewah1).equals(ewah1));
Assert.assertTrue(EWAHCompressedBitmap.threshold(2, ewah2,
ewah2).equals(ewah2));
Assert.assertTrue(EWAHCompressedBitmap.threshold(2, ewah3,
ewah3).equals(ewah3));
EWAHCompressedBitmap zero = new EWAHCompressedBitmap();
Assert.assertTrue(EWAHCompressedBitmap.threshold(2, ewah1).equals(zero));
Assert.assertTrue(EWAHCompressedBitmap.threshold(2, ewah2).equals(zero));
Assert.assertTrue(EWAHCompressedBitmap.threshold(2, ewah3).equals(zero));
Assert.assertTrue(EWAHCompressedBitmap.threshold(4, ewah1,ewah2, ewah3).equals(zero));
EWAHCompressedBitmap ewahorth = EWAHCompressedBitmap.threshold(
1, ewah1, ewah2, ewah3);
EWAHCompressedBitmap ewahtrueor = EWAHCompressedBitmap.or(
ewah1, ewah2, ewah3);
Assert.assertTrue(ewahorth.equals(ewahtrueor));
EWAHCompressedBitmap ewahandth = EWAHCompressedBitmap
.threshold(3, ewah1, ewah2, ewah3); | // Path: src/main/java/com/googlecode/javaewah/EWAHCompressedBitmap.java
// static int maxSizeInBits(final EWAHCompressedBitmap... bitmaps) {
// int maxSizeInBits = 0;
// for(EWAHCompressedBitmap bitmap : bitmaps) {
// maxSizeInBits = Math.max(maxSizeInBits, bitmap.sizeInBits());
// }
// return maxSizeInBits;
// }
// Path: src/test/java/com/googlecode/javaewah/ThresholdFuncBitmapTest.java
import static com.googlecode.javaewah.EWAHCompressedBitmap.maxSizeInBits;
import org.junit.Assert;
import org.junit.Test;
EWAHCompressedBitmap ewah3 = EWAHCompressedBitmap.bitmapOf(1,
110, 1000, 1101, 1200, 1201, 31416, 31417);
Assert.assertTrue(EWAHCompressedBitmap.threshold(1, ewah1)
.equals(ewah1));
Assert.assertTrue(EWAHCompressedBitmap.threshold(1, ewah2)
.equals(ewah2));
Assert.assertTrue(EWAHCompressedBitmap.threshold(1, ewah3)
.equals(ewah3));
Assert.assertTrue(EWAHCompressedBitmap.threshold(2, ewah1,
ewah1).equals(ewah1));
Assert.assertTrue(EWAHCompressedBitmap.threshold(2, ewah2,
ewah2).equals(ewah2));
Assert.assertTrue(EWAHCompressedBitmap.threshold(2, ewah3,
ewah3).equals(ewah3));
EWAHCompressedBitmap zero = new EWAHCompressedBitmap();
Assert.assertTrue(EWAHCompressedBitmap.threshold(2, ewah1).equals(zero));
Assert.assertTrue(EWAHCompressedBitmap.threshold(2, ewah2).equals(zero));
Assert.assertTrue(EWAHCompressedBitmap.threshold(2, ewah3).equals(zero));
Assert.assertTrue(EWAHCompressedBitmap.threshold(4, ewah1,ewah2, ewah3).equals(zero));
EWAHCompressedBitmap ewahorth = EWAHCompressedBitmap.threshold(
1, ewah1, ewah2, ewah3);
EWAHCompressedBitmap ewahtrueor = EWAHCompressedBitmap.or(
ewah1, ewah2, ewah3);
Assert.assertTrue(ewahorth.equals(ewahtrueor));
EWAHCompressedBitmap ewahandth = EWAHCompressedBitmap
.threshold(3, ewah1, ewah2, ewah3); | ewahandth.setSizeInBitsWithinLastWord(maxSizeInBits(ewah1, ewah2, ewah3)); |
mojtaba-khallash/JHazm | JHazm/src/main/java/jhazm/tokenizer/WordTokenizer.java | // Path: JHazm/src/main/java/jhazm/utility/RegexPattern.java
// public class RegexPattern {
// private final String Pattern;
// private final String Replace;
// public RegexPattern(String pattern, String replace) {
// this.Pattern = pattern;
// this.Replace = replace;
// }
//
// public String apply(String text) {
// return text.replaceAll(Pattern, Replace);
// }
// }
| import jhazm.utility.RegexPattern;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.*; | package jhazm.tokenizer;
/**
*
* @author Mojtaba Khallash
*/
public class WordTokenizer {
public static WordTokenizer instance;
List<String> verbs;
private boolean joinVerbParts = true;
private HashSet<String> beforeVerbs;
private HashSet<String> afterVerbs; | // Path: JHazm/src/main/java/jhazm/utility/RegexPattern.java
// public class RegexPattern {
// private final String Pattern;
// private final String Replace;
// public RegexPattern(String pattern, String replace) {
// this.Pattern = pattern;
// this.Replace = replace;
// }
//
// public String apply(String text) {
// return text.replaceAll(Pattern, Replace);
// }
// }
// Path: JHazm/src/main/java/jhazm/tokenizer/WordTokenizer.java
import jhazm.utility.RegexPattern;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.*;
package jhazm.tokenizer;
/**
*
* @author Mojtaba Khallash
*/
public class WordTokenizer {
public static WordTokenizer instance;
List<String> verbs;
private boolean joinVerbParts = true;
private HashSet<String> beforeVerbs;
private HashSet<String> afterVerbs; | private RegexPattern pattern; |
mojtaba-khallash/JHazm | JHazm/src/main/java/jhazm/Normalizer.java | // Path: JHazm/src/main/java/jhazm/utility/MakeTrans.java
// public class MakeTrans {
// private final Map<Character, Character> d;
//
// public MakeTrans(String intab, String outab) {
// d = new HashMap<>();
// for (int i = 0; i < intab.length(); i++)
// d.put(intab.charAt(i), outab.charAt(i));
// }
//
// public String translate(String src) {
// StringBuilder sb = new StringBuilder(src.length());
// for (char src_c : src.toCharArray())
// sb.append(d.containsKey(src_c) ? (Character) d.get(src_c) : src_c);
// return sb.toString();
// }
// }
//
// Path: JHazm/src/main/java/jhazm/utility/RegexPattern.java
// public class RegexPattern {
// private final String Pattern;
// private final String Replace;
// public RegexPattern(String pattern, String replace) {
// this.Pattern = pattern;
// this.Replace = replace;
// }
//
// public String apply(String text) {
// return text.replaceAll(Pattern, Replace);
// }
// }
| import jhazm.utility.MakeTrans;
import jhazm.utility.RegexPattern;
import java.util.ArrayList;
import java.util.List; | package jhazm;
/**
* @author Mojtaba Khallash
*/
public class Normalizer {
public static Normalizer instance;
private final String puncAfter = "!:\\.،؛؟»\\]\\)\\}";
private final String puncBefore = "«\\[\\(\\{";
private boolean characterRefinement = true; | // Path: JHazm/src/main/java/jhazm/utility/MakeTrans.java
// public class MakeTrans {
// private final Map<Character, Character> d;
//
// public MakeTrans(String intab, String outab) {
// d = new HashMap<>();
// for (int i = 0; i < intab.length(); i++)
// d.put(intab.charAt(i), outab.charAt(i));
// }
//
// public String translate(String src) {
// StringBuilder sb = new StringBuilder(src.length());
// for (char src_c : src.toCharArray())
// sb.append(d.containsKey(src_c) ? (Character) d.get(src_c) : src_c);
// return sb.toString();
// }
// }
//
// Path: JHazm/src/main/java/jhazm/utility/RegexPattern.java
// public class RegexPattern {
// private final String Pattern;
// private final String Replace;
// public RegexPattern(String pattern, String replace) {
// this.Pattern = pattern;
// this.Replace = replace;
// }
//
// public String apply(String text) {
// return text.replaceAll(Pattern, Replace);
// }
// }
// Path: JHazm/src/main/java/jhazm/Normalizer.java
import jhazm.utility.MakeTrans;
import jhazm.utility.RegexPattern;
import java.util.ArrayList;
import java.util.List;
package jhazm;
/**
* @author Mojtaba Khallash
*/
public class Normalizer {
public static Normalizer instance;
private final String puncAfter = "!:\\.،؛؟»\\]\\)\\}";
private final String puncBefore = "«\\[\\(\\{";
private boolean characterRefinement = true; | private List<RegexPattern> characterRefinementPatterns; |
mojtaba-khallash/JHazm | JHazm/src/main/java/jhazm/Normalizer.java | // Path: JHazm/src/main/java/jhazm/utility/MakeTrans.java
// public class MakeTrans {
// private final Map<Character, Character> d;
//
// public MakeTrans(String intab, String outab) {
// d = new HashMap<>();
// for (int i = 0; i < intab.length(); i++)
// d.put(intab.charAt(i), outab.charAt(i));
// }
//
// public String translate(String src) {
// StringBuilder sb = new StringBuilder(src.length());
// for (char src_c : src.toCharArray())
// sb.append(d.containsKey(src_c) ? (Character) d.get(src_c) : src_c);
// return sb.toString();
// }
// }
//
// Path: JHazm/src/main/java/jhazm/utility/RegexPattern.java
// public class RegexPattern {
// private final String Pattern;
// private final String Replace;
// public RegexPattern(String pattern, String replace) {
// this.Pattern = pattern;
// this.Replace = replace;
// }
//
// public String apply(String text) {
// return text.replaceAll(Pattern, Replace);
// }
// }
| import jhazm.utility.MakeTrans;
import jhazm.utility.RegexPattern;
import java.util.ArrayList;
import java.util.List; | package jhazm;
/**
* @author Mojtaba Khallash
*/
public class Normalizer {
public static Normalizer instance;
private final String puncAfter = "!:\\.،؛؟»\\]\\)\\}";
private final String puncBefore = "«\\[\\(\\{";
private boolean characterRefinement = true;
private List<RegexPattern> characterRefinementPatterns;
private boolean punctuationSpacing = true;
private List<RegexPattern> punctuationSpacingPatterns;
private boolean affixSpacing = true;
private List<RegexPattern> affixSpacingPatterns; | // Path: JHazm/src/main/java/jhazm/utility/MakeTrans.java
// public class MakeTrans {
// private final Map<Character, Character> d;
//
// public MakeTrans(String intab, String outab) {
// d = new HashMap<>();
// for (int i = 0; i < intab.length(); i++)
// d.put(intab.charAt(i), outab.charAt(i));
// }
//
// public String translate(String src) {
// StringBuilder sb = new StringBuilder(src.length());
// for (char src_c : src.toCharArray())
// sb.append(d.containsKey(src_c) ? (Character) d.get(src_c) : src_c);
// return sb.toString();
// }
// }
//
// Path: JHazm/src/main/java/jhazm/utility/RegexPattern.java
// public class RegexPattern {
// private final String Pattern;
// private final String Replace;
// public RegexPattern(String pattern, String replace) {
// this.Pattern = pattern;
// this.Replace = replace;
// }
//
// public String apply(String text) {
// return text.replaceAll(Pattern, Replace);
// }
// }
// Path: JHazm/src/main/java/jhazm/Normalizer.java
import jhazm.utility.MakeTrans;
import jhazm.utility.RegexPattern;
import java.util.ArrayList;
import java.util.List;
package jhazm;
/**
* @author Mojtaba Khallash
*/
public class Normalizer {
public static Normalizer instance;
private final String puncAfter = "!:\\.،؛؟»\\]\\)\\}";
private final String puncBefore = "«\\[\\(\\{";
private boolean characterRefinement = true;
private List<RegexPattern> characterRefinementPatterns;
private boolean punctuationSpacing = true;
private List<RegexPattern> punctuationSpacingPatterns;
private boolean affixSpacing = true;
private List<RegexPattern> affixSpacingPatterns; | private MakeTrans translations; |
mojtaba-khallash/JHazm | JHazm/src/test/java/jhazm/test/StemmerTests.java | // Path: JHazm/src/main/java/jhazm/Stemmer.java
// public class Stemmer {
// public static Stemmer instance;
// private final String[] ends = new String[] {
// "ات", "ان", "ترین", "تر", "م", "ت", "ش", "یی", "ی", "ها", "ٔ", "ا", //
// };
//
// public static Stemmer i() {
// if (instance != null) return instance;
// instance = new Stemmer();
// return instance;
// }
//
// public String stem(String word) {
// for (String end : this.ends) {
// if (word.endsWith(end)) {
// word = word.substring(0, word.length() - end.length()).trim();
// word = StringUtils.strip(word, "");
// }
// }
//
// if (word.endsWith("ۀ"))
// word = word.substring(0, word.length() - 1) + "ه";
//
// return word;
// }
// }
| import jhazm.Stemmer;
import org.junit.Test;
import static org.junit.Assert.assertEquals; | package jhazm.test;
/**
*
* @author Mojtaba Khallash
*/
public class StemmerTests {
@Test
public void stemTest() { | // Path: JHazm/src/main/java/jhazm/Stemmer.java
// public class Stemmer {
// public static Stemmer instance;
// private final String[] ends = new String[] {
// "ات", "ان", "ترین", "تر", "م", "ت", "ش", "یی", "ی", "ها", "ٔ", "ا", //
// };
//
// public static Stemmer i() {
// if (instance != null) return instance;
// instance = new Stemmer();
// return instance;
// }
//
// public String stem(String word) {
// for (String end : this.ends) {
// if (word.endsWith(end)) {
// word = word.substring(0, word.length() - end.length()).trim();
// word = StringUtils.strip(word, "");
// }
// }
//
// if (word.endsWith("ۀ"))
// word = word.substring(0, word.length() - 1) + "ه";
//
// return word;
// }
// }
// Path: JHazm/src/test/java/jhazm/test/StemmerTests.java
import jhazm.Stemmer;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
package jhazm.test;
/**
*
* @author Mojtaba Khallash
*/
public class StemmerTests {
@Test
public void stemTest() { | Stemmer stemmer = new Stemmer(); |
mojtaba-khallash/JHazm | JHazm/src/test/java/jhazm/test/reader/PersicaReaderTest.java | // Path: JHazm/src/main/java/jhazm/model/Doc.java
// public class Doc {
// public int ID;
// public String Title;
// public String Text;
// public String Date;
// public String Time;
// public String Category;
// public String Category2;
//
// public Doc(int ID, String Title, String Text, String Date, String Time, String Category, String Category2) {
// this.ID = ID;
// this.Title = Title;
// this.Text = Text;
// this.Date = Date;
// this.Time = Time;
// this.Category = Category;
// this.Category2 = Category2;
// }
// }
//
// Path: JHazm/src/main/java/jhazm/reader/PersicaReader.java
// public class PersicaReader {
//
// //
// // Fields
// //
//
// private String persicaFile;
//
//
//
// //
// // Constructors
// //
//
// public PersicaReader() {
// this("resources/corpora/persica.csv");
// }
//
// public PersicaReader(String persicaFile) {
// this.persicaFile = persicaFile;
// }
//
//
//
//
// //
// // API
// //
//
// public Iterable<Doc> getDocs() { return new YieldDoc(); }
//
// public Iterable<String> getTexts() { return new YieldtText(); }
//
//
//
//
//
// //
// // Helper
// //
//
// private String getPersicaFile() {
// return persicaFile;
// }
//
// class YieldDoc extends Yielder<Doc> {
// private BufferedReader br;
//
// public YieldDoc() {
// try {
// FileInputStream fstream = new FileInputStream(getPersicaFile());
// DataInputStream in = new DataInputStream(fstream);
// br = new BufferedReader(new InputStreamReader(in, Charset.forName("UTF8")));
// }
// catch (Exception ex) {
// ex.printStackTrace();
// }
// }
//
// @Override
// protected void yieldNextCore() {
// try {
// List<String> lines = new ArrayList<>();
// String line;
//
// while ((line = br.readLine()) != null) {
// line = line.trim();
// if (line.length() > 0) {
// if (line.endsWith(",")) {
// lines.add(StringUtils.stripEnd(line, ","));
// }
// else {
// lines.add(line);
// yieldReturn(new Doc(
// Integer.parseInt(lines.get(0)), // ID
// lines.get(1), // Title
// lines.get(2), // Text
// lines.get(3), // Date
// lines.get(4), // Time
// lines.get(5), // Category
// lines.get(6))); // Category2
//
// lines = new ArrayList<>();
// return;
// }
// }
// }
// br.close();
// } catch(Exception ex){
// ex.printStackTrace();
// }
// }
// }
//
// class YieldtText extends Yielder<String> {
// private Iterator<Doc> iter;
//
// public YieldtText() {
// try {
// iter = getDocs().iterator();
// }
// catch (Exception ex) {
// ex.printStackTrace();
// }
// }
//
// @Override
// protected void yieldNextCore() {
// try {
// while (iter.hasNext()) {
// Doc doc = iter.next();
// yieldReturn(doc.Text);
// return;
// }
// } catch(Exception ex){
// ex.printStackTrace();
// }
// }
// }
// }
| import jhazm.model.Doc;
import jhazm.reader.PersicaReader;
import org.junit.Test;
import java.util.Iterator;
import static org.junit.Assert.assertEquals; | package jhazm.test.reader;
/**
* Created by Mojtaba on 30/10/2015.
*/
public class PersicaReaderTest {
@Test
public void getDocsTest() { | // Path: JHazm/src/main/java/jhazm/model/Doc.java
// public class Doc {
// public int ID;
// public String Title;
// public String Text;
// public String Date;
// public String Time;
// public String Category;
// public String Category2;
//
// public Doc(int ID, String Title, String Text, String Date, String Time, String Category, String Category2) {
// this.ID = ID;
// this.Title = Title;
// this.Text = Text;
// this.Date = Date;
// this.Time = Time;
// this.Category = Category;
// this.Category2 = Category2;
// }
// }
//
// Path: JHazm/src/main/java/jhazm/reader/PersicaReader.java
// public class PersicaReader {
//
// //
// // Fields
// //
//
// private String persicaFile;
//
//
//
// //
// // Constructors
// //
//
// public PersicaReader() {
// this("resources/corpora/persica.csv");
// }
//
// public PersicaReader(String persicaFile) {
// this.persicaFile = persicaFile;
// }
//
//
//
//
// //
// // API
// //
//
// public Iterable<Doc> getDocs() { return new YieldDoc(); }
//
// public Iterable<String> getTexts() { return new YieldtText(); }
//
//
//
//
//
// //
// // Helper
// //
//
// private String getPersicaFile() {
// return persicaFile;
// }
//
// class YieldDoc extends Yielder<Doc> {
// private BufferedReader br;
//
// public YieldDoc() {
// try {
// FileInputStream fstream = new FileInputStream(getPersicaFile());
// DataInputStream in = new DataInputStream(fstream);
// br = new BufferedReader(new InputStreamReader(in, Charset.forName("UTF8")));
// }
// catch (Exception ex) {
// ex.printStackTrace();
// }
// }
//
// @Override
// protected void yieldNextCore() {
// try {
// List<String> lines = new ArrayList<>();
// String line;
//
// while ((line = br.readLine()) != null) {
// line = line.trim();
// if (line.length() > 0) {
// if (line.endsWith(",")) {
// lines.add(StringUtils.stripEnd(line, ","));
// }
// else {
// lines.add(line);
// yieldReturn(new Doc(
// Integer.parseInt(lines.get(0)), // ID
// lines.get(1), // Title
// lines.get(2), // Text
// lines.get(3), // Date
// lines.get(4), // Time
// lines.get(5), // Category
// lines.get(6))); // Category2
//
// lines = new ArrayList<>();
// return;
// }
// }
// }
// br.close();
// } catch(Exception ex){
// ex.printStackTrace();
// }
// }
// }
//
// class YieldtText extends Yielder<String> {
// private Iterator<Doc> iter;
//
// public YieldtText() {
// try {
// iter = getDocs().iterator();
// }
// catch (Exception ex) {
// ex.printStackTrace();
// }
// }
//
// @Override
// protected void yieldNextCore() {
// try {
// while (iter.hasNext()) {
// Doc doc = iter.next();
// yieldReturn(doc.Text);
// return;
// }
// } catch(Exception ex){
// ex.printStackTrace();
// }
// }
// }
// }
// Path: JHazm/src/test/java/jhazm/test/reader/PersicaReaderTest.java
import jhazm.model.Doc;
import jhazm.reader.PersicaReader;
import org.junit.Test;
import java.util.Iterator;
import static org.junit.Assert.assertEquals;
package jhazm.test.reader;
/**
* Created by Mojtaba on 30/10/2015.
*/
public class PersicaReaderTest {
@Test
public void getDocsTest() { | PersicaReader pr = new PersicaReader(); |
mojtaba-khallash/JHazm | JHazm/src/test/java/jhazm/test/reader/PersicaReaderTest.java | // Path: JHazm/src/main/java/jhazm/model/Doc.java
// public class Doc {
// public int ID;
// public String Title;
// public String Text;
// public String Date;
// public String Time;
// public String Category;
// public String Category2;
//
// public Doc(int ID, String Title, String Text, String Date, String Time, String Category, String Category2) {
// this.ID = ID;
// this.Title = Title;
// this.Text = Text;
// this.Date = Date;
// this.Time = Time;
// this.Category = Category;
// this.Category2 = Category2;
// }
// }
//
// Path: JHazm/src/main/java/jhazm/reader/PersicaReader.java
// public class PersicaReader {
//
// //
// // Fields
// //
//
// private String persicaFile;
//
//
//
// //
// // Constructors
// //
//
// public PersicaReader() {
// this("resources/corpora/persica.csv");
// }
//
// public PersicaReader(String persicaFile) {
// this.persicaFile = persicaFile;
// }
//
//
//
//
// //
// // API
// //
//
// public Iterable<Doc> getDocs() { return new YieldDoc(); }
//
// public Iterable<String> getTexts() { return new YieldtText(); }
//
//
//
//
//
// //
// // Helper
// //
//
// private String getPersicaFile() {
// return persicaFile;
// }
//
// class YieldDoc extends Yielder<Doc> {
// private BufferedReader br;
//
// public YieldDoc() {
// try {
// FileInputStream fstream = new FileInputStream(getPersicaFile());
// DataInputStream in = new DataInputStream(fstream);
// br = new BufferedReader(new InputStreamReader(in, Charset.forName("UTF8")));
// }
// catch (Exception ex) {
// ex.printStackTrace();
// }
// }
//
// @Override
// protected void yieldNextCore() {
// try {
// List<String> lines = new ArrayList<>();
// String line;
//
// while ((line = br.readLine()) != null) {
// line = line.trim();
// if (line.length() > 0) {
// if (line.endsWith(",")) {
// lines.add(StringUtils.stripEnd(line, ","));
// }
// else {
// lines.add(line);
// yieldReturn(new Doc(
// Integer.parseInt(lines.get(0)), // ID
// lines.get(1), // Title
// lines.get(2), // Text
// lines.get(3), // Date
// lines.get(4), // Time
// lines.get(5), // Category
// lines.get(6))); // Category2
//
// lines = new ArrayList<>();
// return;
// }
// }
// }
// br.close();
// } catch(Exception ex){
// ex.printStackTrace();
// }
// }
// }
//
// class YieldtText extends Yielder<String> {
// private Iterator<Doc> iter;
//
// public YieldtText() {
// try {
// iter = getDocs().iterator();
// }
// catch (Exception ex) {
// ex.printStackTrace();
// }
// }
//
// @Override
// protected void yieldNextCore() {
// try {
// while (iter.hasNext()) {
// Doc doc = iter.next();
// yieldReturn(doc.Text);
// return;
// }
// } catch(Exception ex){
// ex.printStackTrace();
// }
// }
// }
// }
| import jhazm.model.Doc;
import jhazm.reader.PersicaReader;
import org.junit.Test;
import java.util.Iterator;
import static org.junit.Assert.assertEquals; | package jhazm.test.reader;
/**
* Created by Mojtaba on 30/10/2015.
*/
public class PersicaReaderTest {
@Test
public void getDocsTest() {
PersicaReader pr = new PersicaReader();
int expected = 843656; | // Path: JHazm/src/main/java/jhazm/model/Doc.java
// public class Doc {
// public int ID;
// public String Title;
// public String Text;
// public String Date;
// public String Time;
// public String Category;
// public String Category2;
//
// public Doc(int ID, String Title, String Text, String Date, String Time, String Category, String Category2) {
// this.ID = ID;
// this.Title = Title;
// this.Text = Text;
// this.Date = Date;
// this.Time = Time;
// this.Category = Category;
// this.Category2 = Category2;
// }
// }
//
// Path: JHazm/src/main/java/jhazm/reader/PersicaReader.java
// public class PersicaReader {
//
// //
// // Fields
// //
//
// private String persicaFile;
//
//
//
// //
// // Constructors
// //
//
// public PersicaReader() {
// this("resources/corpora/persica.csv");
// }
//
// public PersicaReader(String persicaFile) {
// this.persicaFile = persicaFile;
// }
//
//
//
//
// //
// // API
// //
//
// public Iterable<Doc> getDocs() { return new YieldDoc(); }
//
// public Iterable<String> getTexts() { return new YieldtText(); }
//
//
//
//
//
// //
// // Helper
// //
//
// private String getPersicaFile() {
// return persicaFile;
// }
//
// class YieldDoc extends Yielder<Doc> {
// private BufferedReader br;
//
// public YieldDoc() {
// try {
// FileInputStream fstream = new FileInputStream(getPersicaFile());
// DataInputStream in = new DataInputStream(fstream);
// br = new BufferedReader(new InputStreamReader(in, Charset.forName("UTF8")));
// }
// catch (Exception ex) {
// ex.printStackTrace();
// }
// }
//
// @Override
// protected void yieldNextCore() {
// try {
// List<String> lines = new ArrayList<>();
// String line;
//
// while ((line = br.readLine()) != null) {
// line = line.trim();
// if (line.length() > 0) {
// if (line.endsWith(",")) {
// lines.add(StringUtils.stripEnd(line, ","));
// }
// else {
// lines.add(line);
// yieldReturn(new Doc(
// Integer.parseInt(lines.get(0)), // ID
// lines.get(1), // Title
// lines.get(2), // Text
// lines.get(3), // Date
// lines.get(4), // Time
// lines.get(5), // Category
// lines.get(6))); // Category2
//
// lines = new ArrayList<>();
// return;
// }
// }
// }
// br.close();
// } catch(Exception ex){
// ex.printStackTrace();
// }
// }
// }
//
// class YieldtText extends Yielder<String> {
// private Iterator<Doc> iter;
//
// public YieldtText() {
// try {
// iter = getDocs().iterator();
// }
// catch (Exception ex) {
// ex.printStackTrace();
// }
// }
//
// @Override
// protected void yieldNextCore() {
// try {
// while (iter.hasNext()) {
// Doc doc = iter.next();
// yieldReturn(doc.Text);
// return;
// }
// } catch(Exception ex){
// ex.printStackTrace();
// }
// }
// }
// }
// Path: JHazm/src/test/java/jhazm/test/reader/PersicaReaderTest.java
import jhazm.model.Doc;
import jhazm.reader.PersicaReader;
import org.junit.Test;
import java.util.Iterator;
import static org.junit.Assert.assertEquals;
package jhazm.test.reader;
/**
* Created by Mojtaba on 30/10/2015.
*/
public class PersicaReaderTest {
@Test
public void getDocsTest() {
PersicaReader pr = new PersicaReader();
int expected = 843656; | Iterator<Doc> iter = pr.getDocs().iterator(); |
mojtaba-khallash/JHazm | JHazm/src/test/java/jhazm/test/reader/PeykareReaderTest.java | // Path: JHazm/src/main/java/jhazm/reader/PeykareReader.java
// public class PeykareReader {
// private static List<String> cpos;
// private static WordTokenizer tokenizer = null;
//
//
// static {
// try {
// cpos = Arrays.asList(new String[] {
// "N", // Noun
// "V", // Verb
// "AJ", // Adjective
// "ADV", // Adverb
// "PRO", // Pronoun
// "DET", // Determiner
// "P", // Preposition
// "POSTP", // Postposition
// "NUM", // Number
// "CONJ", // Conjunction
// "PUNC", // Punctuation
// "RES", // Residual
// "CL", // Classifier
// "INT" // Interjection
// });
//
// tokenizer = new WordTokenizer();
// } catch (IOException e) {
// }
// }
//
// /**
// * Coarse POS tags of Peykare corpus:
// */
// public static String coarsePOS(List<String> tags) {
// try {
// String result = "N";
// for (String tag : tags) {
// if (cpos.contains(tag)) {
// result = tag;
// break;
// }
// }
//
// if (tags.contains("EZ"))
// result += "e";
// return result;
// }
// catch(Exception ex) {
// return "N";
// }
// }
//
// /**
// * Join verb parts like Dadedgan corpus.
// * Input:
// * دیده/ADJ_INO
// * شد/V_PA
// * Iutput:
// * دیده شد/V_PA
// */
// public static List<TaggedWord> joinVerbParts(List<TaggedWord> sentence) {
// Collections.reverse(sentence);
// List<TaggedWord> result = new ArrayList<>();
// TaggedWord beforeTaggedWord = new TaggedWord("", "");
// for (TaggedWord taggedWord : sentence) {
// if (PeykareReader.tokenizer.getBeforeVerbs().contains(taggedWord.word()) ||
// (PeykareReader.tokenizer.getAfterVerbs().contains(beforeTaggedWord.word()) &&
// PeykareReader.tokenizer.getVerbs().contains(taggedWord.word()))) {
// beforeTaggedWord.setWord(taggedWord.word() + " " + beforeTaggedWord.word());
// if (result.isEmpty())
// result.add(beforeTaggedWord);
// }
// else {
// result.add(taggedWord);
// beforeTaggedWord = taggedWord;
// }
// }
//
// Collections.reverse(result);
// return result;
// }
// }
| import edu.stanford.nlp.ling.TaggedWord;
import jhazm.reader.PeykareReader;
import org.junit.Test;
import java.util.Arrays;
import java.util.List;
import static org.junit.Assert.assertEquals; | package jhazm.test.reader;
/**
* Created by Mojtaba on 30/10/2015.
*/
public class PeykareReaderTest {
@Test
public void coarsePOSTest() {
List<String> input = Arrays.asList(new String[]{ "N", "COM", "SING" });
String expected = "N"; | // Path: JHazm/src/main/java/jhazm/reader/PeykareReader.java
// public class PeykareReader {
// private static List<String> cpos;
// private static WordTokenizer tokenizer = null;
//
//
// static {
// try {
// cpos = Arrays.asList(new String[] {
// "N", // Noun
// "V", // Verb
// "AJ", // Adjective
// "ADV", // Adverb
// "PRO", // Pronoun
// "DET", // Determiner
// "P", // Preposition
// "POSTP", // Postposition
// "NUM", // Number
// "CONJ", // Conjunction
// "PUNC", // Punctuation
// "RES", // Residual
// "CL", // Classifier
// "INT" // Interjection
// });
//
// tokenizer = new WordTokenizer();
// } catch (IOException e) {
// }
// }
//
// /**
// * Coarse POS tags of Peykare corpus:
// */
// public static String coarsePOS(List<String> tags) {
// try {
// String result = "N";
// for (String tag : tags) {
// if (cpos.contains(tag)) {
// result = tag;
// break;
// }
// }
//
// if (tags.contains("EZ"))
// result += "e";
// return result;
// }
// catch(Exception ex) {
// return "N";
// }
// }
//
// /**
// * Join verb parts like Dadedgan corpus.
// * Input:
// * دیده/ADJ_INO
// * شد/V_PA
// * Iutput:
// * دیده شد/V_PA
// */
// public static List<TaggedWord> joinVerbParts(List<TaggedWord> sentence) {
// Collections.reverse(sentence);
// List<TaggedWord> result = new ArrayList<>();
// TaggedWord beforeTaggedWord = new TaggedWord("", "");
// for (TaggedWord taggedWord : sentence) {
// if (PeykareReader.tokenizer.getBeforeVerbs().contains(taggedWord.word()) ||
// (PeykareReader.tokenizer.getAfterVerbs().contains(beforeTaggedWord.word()) &&
// PeykareReader.tokenizer.getVerbs().contains(taggedWord.word()))) {
// beforeTaggedWord.setWord(taggedWord.word() + " " + beforeTaggedWord.word());
// if (result.isEmpty())
// result.add(beforeTaggedWord);
// }
// else {
// result.add(taggedWord);
// beforeTaggedWord = taggedWord;
// }
// }
//
// Collections.reverse(result);
// return result;
// }
// }
// Path: JHazm/src/test/java/jhazm/test/reader/PeykareReaderTest.java
import edu.stanford.nlp.ling.TaggedWord;
import jhazm.reader.PeykareReader;
import org.junit.Test;
import java.util.Arrays;
import java.util.List;
import static org.junit.Assert.assertEquals;
package jhazm.test.reader;
/**
* Created by Mojtaba on 30/10/2015.
*/
public class PeykareReaderTest {
@Test
public void coarsePOSTest() {
List<String> input = Arrays.asList(new String[]{ "N", "COM", "SING" });
String expected = "N"; | String actual = PeykareReader.coarsePOS(input); |
mojtaba-khallash/JHazm | JHazm/src/test/java/jhazm/test/POSTaggerTest.java | // Path: JHazm/src/main/java/jhazm/POSTagger.java
// public class POSTagger {
// public static POSTagger instance;
// private MaxentTagger tagger;
//
// public POSTagger() throws IOException {
// this("resources/models/persian.tagger");
// }
//
// public POSTagger(String pathToModel) throws IOException {
// this.tagger = new MaxentTagger(pathToModel);
// }
//
// public static POSTagger i() throws IOException {
// if (instance != null) return instance;
// instance = new POSTagger();
// return instance;
// }
//
// public List<List<TaggedWord>> batchTags(List<List<String>> sentences) {
// List<List<TaggedWord>> result = new ArrayList<>();
//
// for (List<String> sentence : sentences) {
// result.add(batchTag(sentence));
// }
//
// return result;
// }
//
// public List<TaggedWord> batchTag(List<String> sentence) {
// String[] sen = new String[sentence.size()];
// for (int i = 0; i < sentence.size(); i++)
// sen[i] = sentence.get(i).replace(" ", "_");
// List newSent = Sentence.toWordList(sen);
// List taggedSentence = this.tagger.tagSentence(newSent);
//
// List<TaggedWord> taggedSen = new ArrayList<>();
// for (int i = 0; i < taggedSentence.size(); i++) {
// TaggedWord tw = (TaggedWord)taggedSentence.get(i);
// tw.setWord(sentence.get(i));
// taggedSen.add(tw);
// }
// return taggedSen;
// }
// }
| import edu.stanford.nlp.ling.TaggedWord;
import edu.stanford.nlp.util.StringUtils;
import jhazm.POSTagger;
import org.junit.Test;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static org.junit.Assert.assertEquals; | package jhazm.test;
/**
*
* @author Mojtaba Khallash
*/
public class POSTaggerTest {
@Test
public void batchTagTest() throws IOException { | // Path: JHazm/src/main/java/jhazm/POSTagger.java
// public class POSTagger {
// public static POSTagger instance;
// private MaxentTagger tagger;
//
// public POSTagger() throws IOException {
// this("resources/models/persian.tagger");
// }
//
// public POSTagger(String pathToModel) throws IOException {
// this.tagger = new MaxentTagger(pathToModel);
// }
//
// public static POSTagger i() throws IOException {
// if (instance != null) return instance;
// instance = new POSTagger();
// return instance;
// }
//
// public List<List<TaggedWord>> batchTags(List<List<String>> sentences) {
// List<List<TaggedWord>> result = new ArrayList<>();
//
// for (List<String> sentence : sentences) {
// result.add(batchTag(sentence));
// }
//
// return result;
// }
//
// public List<TaggedWord> batchTag(List<String> sentence) {
// String[] sen = new String[sentence.size()];
// for (int i = 0; i < sentence.size(); i++)
// sen[i] = sentence.get(i).replace(" ", "_");
// List newSent = Sentence.toWordList(sen);
// List taggedSentence = this.tagger.tagSentence(newSent);
//
// List<TaggedWord> taggedSen = new ArrayList<>();
// for (int i = 0; i < taggedSentence.size(); i++) {
// TaggedWord tw = (TaggedWord)taggedSentence.get(i);
// tw.setWord(sentence.get(i));
// taggedSen.add(tw);
// }
// return taggedSen;
// }
// }
// Path: JHazm/src/test/java/jhazm/test/POSTaggerTest.java
import edu.stanford.nlp.ling.TaggedWord;
import edu.stanford.nlp.util.StringUtils;
import jhazm.POSTagger;
import org.junit.Test;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static org.junit.Assert.assertEquals;
package jhazm.test;
/**
*
* @author Mojtaba Khallash
*/
public class POSTaggerTest {
@Test
public void batchTagTest() throws IOException { | POSTagger tagger = new POSTagger(); |
mojtaba-khallash/JHazm | JHazm/src/main/java/jhazm/tokenizer/SentenceTokenizer.java | // Path: JHazm/src/main/java/jhazm/utility/RegexPattern.java
// public class RegexPattern {
// private final String Pattern;
// private final String Replace;
// public RegexPattern(String pattern, String replace) {
// this.Pattern = pattern;
// this.Replace = replace;
// }
//
// public String apply(String text) {
// return text.replaceAll(Pattern, Replace);
// }
// }
| import jhazm.utility.RegexPattern;
import java.util.Arrays;
import java.util.List; | package jhazm.tokenizer;
/**
* @author Mojtaba Khallash
*/
public class SentenceTokenizer {
public static SentenceTokenizer instance; | // Path: JHazm/src/main/java/jhazm/utility/RegexPattern.java
// public class RegexPattern {
// private final String Pattern;
// private final String Replace;
// public RegexPattern(String pattern, String replace) {
// this.Pattern = pattern;
// this.Replace = replace;
// }
//
// public String apply(String text) {
// return text.replaceAll(Pattern, Replace);
// }
// }
// Path: JHazm/src/main/java/jhazm/tokenizer/SentenceTokenizer.java
import jhazm.utility.RegexPattern;
import java.util.Arrays;
import java.util.List;
package jhazm.tokenizer;
/**
* @author Mojtaba Khallash
*/
public class SentenceTokenizer {
public static SentenceTokenizer instance; | private final RegexPattern pattern; |
mojtaba-khallash/JHazm | JHazm/src/test/java/jhazm/test/tokenizer/SentenceTokenizerTests.java | // Path: JHazm/src/main/java/jhazm/tokenizer/SentenceTokenizer.java
// public class SentenceTokenizer {
// public static SentenceTokenizer instance;
// private final RegexPattern pattern;
//
// public SentenceTokenizer() {
// this.pattern = new RegexPattern("([!\\.\\?⸮؟]+)[ \\n]+", "$1\n\n");
// }
//
// public static SentenceTokenizer i() {
// if (instance != null) return instance;
// instance = new SentenceTokenizer();
// return instance;
// }
//
// public List<String> tokenize(String text) {
// text = this.pattern.apply(text);
// List<String> sentences = Arrays.asList(text.split("\n\n"));
// for (String sentence : sentences) {
// sentence = sentence.replace("\n", " ").trim();
// }
// return sentences;
// }
// }
| import jhazm.tokenizer.SentenceTokenizer;
import org.junit.Test;
import java.util.List;
import static org.junit.Assert.assertEquals; | package jhazm.test.tokenizer;
/**
*
* @author Mojtaba Khallash
*/
public class SentenceTokenizerTests {
public SentenceTokenizerTests() {
}
@Test
public void tokenizeTest() { | // Path: JHazm/src/main/java/jhazm/tokenizer/SentenceTokenizer.java
// public class SentenceTokenizer {
// public static SentenceTokenizer instance;
// private final RegexPattern pattern;
//
// public SentenceTokenizer() {
// this.pattern = new RegexPattern("([!\\.\\?⸮؟]+)[ \\n]+", "$1\n\n");
// }
//
// public static SentenceTokenizer i() {
// if (instance != null) return instance;
// instance = new SentenceTokenizer();
// return instance;
// }
//
// public List<String> tokenize(String text) {
// text = this.pattern.apply(text);
// List<String> sentences = Arrays.asList(text.split("\n\n"));
// for (String sentence : sentences) {
// sentence = sentence.replace("\n", " ").trim();
// }
// return sentences;
// }
// }
// Path: JHazm/src/test/java/jhazm/test/tokenizer/SentenceTokenizerTests.java
import jhazm.tokenizer.SentenceTokenizer;
import org.junit.Test;
import java.util.List;
import static org.junit.Assert.assertEquals;
package jhazm.test.tokenizer;
/**
*
* @author Mojtaba Khallash
*/
public class SentenceTokenizerTests {
public SentenceTokenizerTests() {
}
@Test
public void tokenizeTest() { | SentenceTokenizer senTokenizer = new SentenceTokenizer(); |
mojtaba-khallash/JHazm | JHazm/src/main/java/jhazm/reader/PersicaReader.java | // Path: JHazm/src/main/java/jhazm/model/Doc.java
// public class Doc {
// public int ID;
// public String Title;
// public String Text;
// public String Date;
// public String Time;
// public String Category;
// public String Category2;
//
// public Doc(int ID, String Title, String Text, String Date, String Time, String Category, String Category2) {
// this.ID = ID;
// this.Title = Title;
// this.Text = Text;
// this.Date = Date;
// this.Time = Time;
// this.Category = Category;
// this.Category2 = Category2;
// }
// }
| import com.infomancers.collections.yield.Yielder;
import jhazm.model.Doc;
import org.apache.commons.lang3.StringUtils;
import java.io.*;
import java.nio.charset.Charset;
import java.util.*; | package jhazm.reader;
/**
* interfaces [Persica Corpus](https://sourceforge.net/projects/persica/)
*
* Created by Mojtaba on 30/10/2015.
*/
public class PersicaReader {
//
// Fields
//
private String persicaFile;
//
// Constructors
//
public PersicaReader() {
this("resources/corpora/persica.csv");
}
public PersicaReader(String persicaFile) {
this.persicaFile = persicaFile;
}
//
// API
//
| // Path: JHazm/src/main/java/jhazm/model/Doc.java
// public class Doc {
// public int ID;
// public String Title;
// public String Text;
// public String Date;
// public String Time;
// public String Category;
// public String Category2;
//
// public Doc(int ID, String Title, String Text, String Date, String Time, String Category, String Category2) {
// this.ID = ID;
// this.Title = Title;
// this.Text = Text;
// this.Date = Date;
// this.Time = Time;
// this.Category = Category;
// this.Category2 = Category2;
// }
// }
// Path: JHazm/src/main/java/jhazm/reader/PersicaReader.java
import com.infomancers.collections.yield.Yielder;
import jhazm.model.Doc;
import org.apache.commons.lang3.StringUtils;
import java.io.*;
import java.nio.charset.Charset;
import java.util.*;
package jhazm.reader;
/**
* interfaces [Persica Corpus](https://sourceforge.net/projects/persica/)
*
* Created by Mojtaba on 30/10/2015.
*/
public class PersicaReader {
//
// Fields
//
private String persicaFile;
//
// Constructors
//
public PersicaReader() {
this("resources/corpora/persica.csv");
}
public PersicaReader(String persicaFile) {
this.persicaFile = persicaFile;
}
//
// API
//
| public Iterable<Doc> getDocs() { return new YieldDoc(); } |
mojtaba-khallash/JHazm | JHazm/src/main/java/jhazm/reader/VerbValencyReader.java | // Path: JHazm/src/main/java/jhazm/model/Verb.java
// public class Verb {
// public String PastLightVerb;
// public String PresentLightVerb;
// public String Prefix;
// public String NonVerbalElement;
// public String Preposition;
// public String Valency;
//
// public Verb(String PastLightVerb, String PresentLightVerb, String Prefix,
// String NonVerbalElement, String Preposition, String Valency) {
// this.PastLightVerb = PastLightVerb;
// this.PresentLightVerb = PresentLightVerb;
// this.Prefix = Prefix;
// this.NonVerbalElement = NonVerbalElement;
// this.Preposition = Preposition;
// this.Valency = Valency;
// }
// }
| import com.infomancers.collections.yield.Yielder;
import jhazm.model.Verb;
import java.io.*;
import java.nio.charset.Charset; | package jhazm.reader;
/**
* interfaces [Verb Valency Corpus](http://dadegan.ir/catalog/pervallex)
* Mohammad Sadegh Rasooli, Amirsaeid Moloodi, Manouchehr Kouhestani, & Behrouz Minaei Bidgoli. (2011). A Syntactic Valency Lexicon for Persian Verbs: The First Steps towards Persian Dependency Treebank. in 5th Language & Technology Conference(LTC): Human Language Technologies as a Challenge for Computer Science and Linguistics(pp. 227�231). Pozna?, Poland.
*
* Created by Mojtaba Khallash on 30/10/2015.
*/
public class VerbValencyReader {
//
// Fields
//
private String valencyFile;
//
// Constructors
//
public VerbValencyReader() {
this("resources/corpora/valency.txt");
}
public VerbValencyReader(String valencyFile) {
this.valencyFile = valencyFile;
}
//
// API
//
| // Path: JHazm/src/main/java/jhazm/model/Verb.java
// public class Verb {
// public String PastLightVerb;
// public String PresentLightVerb;
// public String Prefix;
// public String NonVerbalElement;
// public String Preposition;
// public String Valency;
//
// public Verb(String PastLightVerb, String PresentLightVerb, String Prefix,
// String NonVerbalElement, String Preposition, String Valency) {
// this.PastLightVerb = PastLightVerb;
// this.PresentLightVerb = PresentLightVerb;
// this.Prefix = Prefix;
// this.NonVerbalElement = NonVerbalElement;
// this.Preposition = Preposition;
// this.Valency = Valency;
// }
// }
// Path: JHazm/src/main/java/jhazm/reader/VerbValencyReader.java
import com.infomancers.collections.yield.Yielder;
import jhazm.model.Verb;
import java.io.*;
import java.nio.charset.Charset;
package jhazm.reader;
/**
* interfaces [Verb Valency Corpus](http://dadegan.ir/catalog/pervallex)
* Mohammad Sadegh Rasooli, Amirsaeid Moloodi, Manouchehr Kouhestani, & Behrouz Minaei Bidgoli. (2011). A Syntactic Valency Lexicon for Persian Verbs: The First Steps towards Persian Dependency Treebank. in 5th Language & Technology Conference(LTC): Human Language Technologies as a Challenge for Computer Science and Linguistics(pp. 227�231). Pozna?, Poland.
*
* Created by Mojtaba Khallash on 30/10/2015.
*/
public class VerbValencyReader {
//
// Fields
//
private String valencyFile;
//
// Constructors
//
public VerbValencyReader() {
this("resources/corpora/valency.txt");
}
public VerbValencyReader(String valencyFile) {
this.valencyFile = valencyFile;
}
//
// API
//
| public Iterable<Verb> getVerbs() throws IOException { return new YieldVernValency(); } |
mojtaba-khallash/JHazm | JHazm/src/test/java/jhazm/test/reader/BijankhanReaderTest.java | // Path: JHazm/src/main/java/jhazm/reader/BijankhanReader.java
// public class BijankhanReader {
// //
// // Fields
// //
//
// private final String[] punctuation = new String[] { "#", "*", ".", "؟", "!" };
//
// private String bijankhanFile;
// private boolean joinedVerbParts;
// private String posMap;
// private Normalizer normalizer;
// private WordTokenizer tokenizer;
//
//
//
// //
// // Constructors
// //
//
// public BijankhanReader() throws IOException {
// this("resources/corpora/bijankhan.txt", true, "resources/data/posMaps.dat");
// }
//
// public BijankhanReader(boolean joinedVerbParts) throws IOException {
// this("resources/corpora/bijankhan.txt", joinedVerbParts, "resources/data/posMaps.dat");
// }
//
// public BijankhanReader(String posMap) throws IOException {
// this("resources/corpora/bijankhan.txt", true, posMap);
// }
//
// public BijankhanReader(boolean joinedVerbParts, String posMap)
// throws IOException {
// this("resources/corpora/bijankhan.txt", joinedVerbParts, posMap);
// }
//
// public BijankhanReader(String bijankhanFile, boolean joinedVerbParts, String posMap)
// throws IOException {
// this.bijankhanFile = bijankhanFile;
// this.joinedVerbParts = joinedVerbParts;
// this.posMap = posMap;
// this.normalizer = new Normalizer(true, false, true);
// this.tokenizer = new WordTokenizer();
// }
//
//
//
//
// //
// // API
// //
//
// public Iterable<List<TaggedWord>> getSentences() {
// return new YieldSentence();
// }
//
//
//
//
//
// //
// // Helper
// //
//
// private String getBijankhanFile() {
// return bijankhanFile;
// }
//
// private boolean isJoinedVerbParts() {
// return joinedVerbParts;
// }
//
// private HashMap getPosMap() throws IOException {
// if (this.posMap != null) {
// HashMap mapper = new HashMap();
// for (String line : Files.readAllLines(Paths.get(this.posMap), Charset.forName("UTF8"))) {
// String[] parts = line.split(",");
// mapper.put(parts[0], parts[1]);
// }
//
// return mapper;
// }
// else
// return null;
// }
//
// private Normalizer getNormalizer() {
// return normalizer;
// }
//
// class YieldSentence extends Yielder<List<TaggedWord>> {
// private BufferedReader br;
//
// public YieldSentence() {
// try {
// FileInputStream fstream = new FileInputStream(getBijankhanFile());
// DataInputStream in = new DataInputStream(fstream);
// br = new BufferedReader(new InputStreamReader(in, Charset.forName("UTF8")));
// }
// catch (Exception ex) {
// ex.printStackTrace();
// }
// }
//
// @Override
// protected void yieldNextCore() {
// try {
// HashMap mapper = getPosMap();
// List<TaggedWord> sentence = new ArrayList<>();
//
// String line;
//
// while ((line = br.readLine()) != null) {
// String[] parts = line.trim().split(" +");
// if (parts.length == 2) {
// String word = parts[0];
// String tag = parts[1];
// if (!(word.equals("#") || word.equals("*"))) {
// word = getNormalizer().run(word);
// if (word.isEmpty())
// word = "_";
// sentence.add(new TaggedWord(word, tag));
// }
// if (tag.equals("DELM") && Arrays.asList(punctuation).contains(word)) {
// if (!sentence.isEmpty()) {
// if (isJoinedVerbParts())
// sentence = PeykareReader.joinVerbParts(sentence);
//
// if (mapper != null) {
// for (TaggedWord tword : sentence) {
// tword.setTag(mapper.get(tword.tag()).toString());
// }
// }
//
// yieldReturn(sentence);
// return;
// }
// }
// }
// }
// br.close();
// } catch(Exception ex){
// ex.printStackTrace();
// }
// }
// }
// }
| import edu.stanford.nlp.ling.TaggedWord;
import jhazm.reader.BijankhanReader;
import org.junit.Test;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import static org.junit.Assert.assertEquals; | package jhazm.test.reader;
/**
*
* @author Mojtaba Khallash
*/
public class BijankhanReaderTest {
@Test
public void posMapTest() throws IOException { | // Path: JHazm/src/main/java/jhazm/reader/BijankhanReader.java
// public class BijankhanReader {
// //
// // Fields
// //
//
// private final String[] punctuation = new String[] { "#", "*", ".", "؟", "!" };
//
// private String bijankhanFile;
// private boolean joinedVerbParts;
// private String posMap;
// private Normalizer normalizer;
// private WordTokenizer tokenizer;
//
//
//
// //
// // Constructors
// //
//
// public BijankhanReader() throws IOException {
// this("resources/corpora/bijankhan.txt", true, "resources/data/posMaps.dat");
// }
//
// public BijankhanReader(boolean joinedVerbParts) throws IOException {
// this("resources/corpora/bijankhan.txt", joinedVerbParts, "resources/data/posMaps.dat");
// }
//
// public BijankhanReader(String posMap) throws IOException {
// this("resources/corpora/bijankhan.txt", true, posMap);
// }
//
// public BijankhanReader(boolean joinedVerbParts, String posMap)
// throws IOException {
// this("resources/corpora/bijankhan.txt", joinedVerbParts, posMap);
// }
//
// public BijankhanReader(String bijankhanFile, boolean joinedVerbParts, String posMap)
// throws IOException {
// this.bijankhanFile = bijankhanFile;
// this.joinedVerbParts = joinedVerbParts;
// this.posMap = posMap;
// this.normalizer = new Normalizer(true, false, true);
// this.tokenizer = new WordTokenizer();
// }
//
//
//
//
// //
// // API
// //
//
// public Iterable<List<TaggedWord>> getSentences() {
// return new YieldSentence();
// }
//
//
//
//
//
// //
// // Helper
// //
//
// private String getBijankhanFile() {
// return bijankhanFile;
// }
//
// private boolean isJoinedVerbParts() {
// return joinedVerbParts;
// }
//
// private HashMap getPosMap() throws IOException {
// if (this.posMap != null) {
// HashMap mapper = new HashMap();
// for (String line : Files.readAllLines(Paths.get(this.posMap), Charset.forName("UTF8"))) {
// String[] parts = line.split(",");
// mapper.put(parts[0], parts[1]);
// }
//
// return mapper;
// }
// else
// return null;
// }
//
// private Normalizer getNormalizer() {
// return normalizer;
// }
//
// class YieldSentence extends Yielder<List<TaggedWord>> {
// private BufferedReader br;
//
// public YieldSentence() {
// try {
// FileInputStream fstream = new FileInputStream(getBijankhanFile());
// DataInputStream in = new DataInputStream(fstream);
// br = new BufferedReader(new InputStreamReader(in, Charset.forName("UTF8")));
// }
// catch (Exception ex) {
// ex.printStackTrace();
// }
// }
//
// @Override
// protected void yieldNextCore() {
// try {
// HashMap mapper = getPosMap();
// List<TaggedWord> sentence = new ArrayList<>();
//
// String line;
//
// while ((line = br.readLine()) != null) {
// String[] parts = line.trim().split(" +");
// if (parts.length == 2) {
// String word = parts[0];
// String tag = parts[1];
// if (!(word.equals("#") || word.equals("*"))) {
// word = getNormalizer().run(word);
// if (word.isEmpty())
// word = "_";
// sentence.add(new TaggedWord(word, tag));
// }
// if (tag.equals("DELM") && Arrays.asList(punctuation).contains(word)) {
// if (!sentence.isEmpty()) {
// if (isJoinedVerbParts())
// sentence = PeykareReader.joinVerbParts(sentence);
//
// if (mapper != null) {
// for (TaggedWord tword : sentence) {
// tword.setTag(mapper.get(tword.tag()).toString());
// }
// }
//
// yieldReturn(sentence);
// return;
// }
// }
// }
// }
// br.close();
// } catch(Exception ex){
// ex.printStackTrace();
// }
// }
// }
// }
// Path: JHazm/src/test/java/jhazm/test/reader/BijankhanReaderTest.java
import edu.stanford.nlp.ling.TaggedWord;
import jhazm.reader.BijankhanReader;
import org.junit.Test;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import static org.junit.Assert.assertEquals;
package jhazm.test.reader;
/**
*
* @author Mojtaba Khallash
*/
public class BijankhanReaderTest {
@Test
public void posMapTest() throws IOException { | BijankhanReader reader = new BijankhanReader(false); |
mojtaba-khallash/JHazm | JHazm/src/test/java/jhazm/test/NormalizerTests.java | // Path: JHazm/src/main/java/jhazm/Normalizer.java
// public class Normalizer {
// public static Normalizer instance;
// private final String puncAfter = "!:\\.،؛؟»\\]\\)\\}";
// private final String puncBefore = "«\\[\\(\\{";
// private boolean characterRefinement = true;
// private List<RegexPattern> characterRefinementPatterns;
// private boolean punctuationSpacing = true;
// private List<RegexPattern> punctuationSpacingPatterns;
// private boolean affixSpacing = true;
// private List<RegexPattern> affixSpacingPatterns;
// private MakeTrans translations;
//
// public Normalizer() {
// this(true, true, true);
// }
//
// public Normalizer(boolean characterRefinement, boolean punctuationSpacing, boolean affixSpacing) {
// this.characterRefinement = characterRefinement;
// this.punctuationSpacing = punctuationSpacing;
// this.affixSpacing = affixSpacing;
//
// this.translations = new MakeTrans(" كي;%1234567890", " کی؛٪۱۲۳۴۵۶۷۸۹۰");
//
//
// if (this.characterRefinement) {
// this.characterRefinementPatterns = new ArrayList<>();
// // remove "keshide" and "carriage return" characters
// this.characterRefinementPatterns.add(new RegexPattern("[ـ\\r]", ""));
// // remove extra spaces
// this.characterRefinementPatterns.add(new RegexPattern(" +", " "));
// // remove extra newlines
// this.characterRefinementPatterns.add(new RegexPattern("\n\n+", "\n\n"));
// // replace 3 dots
// this.characterRefinementPatterns.add(new RegexPattern(" ?\\.\\.\\.", " …"));
// }
//
// if (this.punctuationSpacing) {
// this.punctuationSpacingPatterns = new ArrayList<>();
// // remove space before punctuation
// this.punctuationSpacingPatterns.add(new RegexPattern(" ([" + puncAfter + "])", "$1"));
// // remove space after punctuation
// this.punctuationSpacingPatterns.add(new RegexPattern("([" + puncBefore + "]) ", "$1"));
// // put space after
// this.punctuationSpacingPatterns.add(new RegexPattern("([" + puncAfter + "])([^ " + puncAfter + "])", "$1 $2"));
// // put space before
// this.punctuationSpacingPatterns.add(new RegexPattern("([^ " + puncBefore + "])([" + puncBefore + "])", "$1 $2"));
// }
//
// if (this.affixSpacing) {
// this.affixSpacingPatterns = new ArrayList<>();
// // fix ی space
// this.affixSpacingPatterns.add(new RegexPattern("([^ ]ه) ی ", "$1ی "));
// // put zwnj after می, نمی
// this.affixSpacingPatterns.add(new RegexPattern("(^| )(ن?می) ", "$1$2"));
// // put zwnj before تر, ترین, ها, های
// this.affixSpacingPatterns.add(new RegexPattern(" (تر(ی(ن)?)?|ها(ی)?)(?=[ \n" + puncAfter + puncBefore + "]|$)", "$1"));
// // join ام, ات, اش, ای
// this.affixSpacingPatterns.add(new RegexPattern("([^ ]ه) (ا(م|ت|ش|ی))(?=[ \n" + puncAfter + "]|$)", "$1$2"));
// }
// }
//
// public static Normalizer i() {
// if (instance != null) return instance;
// instance = new Normalizer();
// return instance;
// }
//
// public String run(String text) {
// if (this.characterRefinement)
// text = characterRefinement(text);
//
// if (this.punctuationSpacing)
// text = punctuationSpacing(text);
//
// if (this.affixSpacing)
// text = affixSpacing(text);
//
// return text;
// }
//
// private String characterRefinement(String text) {
// text = this.translations.translate(text);
// for (RegexPattern pattern : this.characterRefinementPatterns)
// text = pattern.apply(text);
// return text;
// }
//
// private String punctuationSpacing(String text) {
// // TODO: don't put space inside time and float numbers
// for (RegexPattern pattern : this.punctuationSpacingPatterns)
// text = pattern.apply(text);
// return text;
// }
//
// private String affixSpacing(String text) {
// for (RegexPattern pattern : this.affixSpacingPatterns)
// text = pattern.apply(text);
// return text;
// }
// }
| import jhazm.Normalizer;
import org.junit.Test;
import static org.junit.Assert.assertEquals; | package jhazm.test;
/**
*
* @author Mojtaba Khallash
*/
public class NormalizerTests {
@Test
public void characterRefinementTest() { | // Path: JHazm/src/main/java/jhazm/Normalizer.java
// public class Normalizer {
// public static Normalizer instance;
// private final String puncAfter = "!:\\.،؛؟»\\]\\)\\}";
// private final String puncBefore = "«\\[\\(\\{";
// private boolean characterRefinement = true;
// private List<RegexPattern> characterRefinementPatterns;
// private boolean punctuationSpacing = true;
// private List<RegexPattern> punctuationSpacingPatterns;
// private boolean affixSpacing = true;
// private List<RegexPattern> affixSpacingPatterns;
// private MakeTrans translations;
//
// public Normalizer() {
// this(true, true, true);
// }
//
// public Normalizer(boolean characterRefinement, boolean punctuationSpacing, boolean affixSpacing) {
// this.characterRefinement = characterRefinement;
// this.punctuationSpacing = punctuationSpacing;
// this.affixSpacing = affixSpacing;
//
// this.translations = new MakeTrans(" كي;%1234567890", " کی؛٪۱۲۳۴۵۶۷۸۹۰");
//
//
// if (this.characterRefinement) {
// this.characterRefinementPatterns = new ArrayList<>();
// // remove "keshide" and "carriage return" characters
// this.characterRefinementPatterns.add(new RegexPattern("[ـ\\r]", ""));
// // remove extra spaces
// this.characterRefinementPatterns.add(new RegexPattern(" +", " "));
// // remove extra newlines
// this.characterRefinementPatterns.add(new RegexPattern("\n\n+", "\n\n"));
// // replace 3 dots
// this.characterRefinementPatterns.add(new RegexPattern(" ?\\.\\.\\.", " …"));
// }
//
// if (this.punctuationSpacing) {
// this.punctuationSpacingPatterns = new ArrayList<>();
// // remove space before punctuation
// this.punctuationSpacingPatterns.add(new RegexPattern(" ([" + puncAfter + "])", "$1"));
// // remove space after punctuation
// this.punctuationSpacingPatterns.add(new RegexPattern("([" + puncBefore + "]) ", "$1"));
// // put space after
// this.punctuationSpacingPatterns.add(new RegexPattern("([" + puncAfter + "])([^ " + puncAfter + "])", "$1 $2"));
// // put space before
// this.punctuationSpacingPatterns.add(new RegexPattern("([^ " + puncBefore + "])([" + puncBefore + "])", "$1 $2"));
// }
//
// if (this.affixSpacing) {
// this.affixSpacingPatterns = new ArrayList<>();
// // fix ی space
// this.affixSpacingPatterns.add(new RegexPattern("([^ ]ه) ی ", "$1ی "));
// // put zwnj after می, نمی
// this.affixSpacingPatterns.add(new RegexPattern("(^| )(ن?می) ", "$1$2"));
// // put zwnj before تر, ترین, ها, های
// this.affixSpacingPatterns.add(new RegexPattern(" (تر(ی(ن)?)?|ها(ی)?)(?=[ \n" + puncAfter + puncBefore + "]|$)", "$1"));
// // join ام, ات, اش, ای
// this.affixSpacingPatterns.add(new RegexPattern("([^ ]ه) (ا(م|ت|ش|ی))(?=[ \n" + puncAfter + "]|$)", "$1$2"));
// }
// }
//
// public static Normalizer i() {
// if (instance != null) return instance;
// instance = new Normalizer();
// return instance;
// }
//
// public String run(String text) {
// if (this.characterRefinement)
// text = characterRefinement(text);
//
// if (this.punctuationSpacing)
// text = punctuationSpacing(text);
//
// if (this.affixSpacing)
// text = affixSpacing(text);
//
// return text;
// }
//
// private String characterRefinement(String text) {
// text = this.translations.translate(text);
// for (RegexPattern pattern : this.characterRefinementPatterns)
// text = pattern.apply(text);
// return text;
// }
//
// private String punctuationSpacing(String text) {
// // TODO: don't put space inside time and float numbers
// for (RegexPattern pattern : this.punctuationSpacingPatterns)
// text = pattern.apply(text);
// return text;
// }
//
// private String affixSpacing(String text) {
// for (RegexPattern pattern : this.affixSpacingPatterns)
// text = pattern.apply(text);
// return text;
// }
// }
// Path: JHazm/src/test/java/jhazm/test/NormalizerTests.java
import jhazm.Normalizer;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
package jhazm.test;
/**
*
* @author Mojtaba Khallash
*/
public class NormalizerTests {
@Test
public void characterRefinementTest() { | Normalizer normalizer = new Normalizer(true, false, false); |
mojtaba-khallash/JHazm | JHazm/src/main/java/jhazm/reader/HamshahriReader.java | // Path: JHazm/src/main/java/jhazm/model/Document.java
// public class Document {
// private String ID;
// private String Number;
// private String OriginalFile;
// private String Issue;
// private String WesternDate;
// private String PersianDate;
// private String EnglishCategory;
// private String PersianCategory;
// private String Title;
// private String Body;
//
// public String getID() { return ID; }
//
// public void setID(String ID) { this.ID = ID; }
//
// public String getNumber() { return Number; }
//
// public void setNumber(String Number) { this.Number = Number; }
//
// public String getOriginalFile() { return OriginalFile; }
//
// public void setOriginalFile(String OriginalFile) { this.OriginalFile = OriginalFile; }
//
// public String getIssue() { return Issue; }
//
// public void setIssue(String Issue) { this.Issue = Issue; }
//
// public String getWesternDate() { return WesternDate; }
//
// public void setWesternDate(String WesternDate) { this.WesternDate = WesternDate; }
//
// public String getPersianDate() { return PersianDate; }
//
// public void setPersianDate(String PersianDate) { this.PersianDate = PersianDate; }
//
// public String getEnglishCategory() { return EnglishCategory; }
//
// public void setEnglishCategory(String EnglishCategory) { this.EnglishCategory = EnglishCategory; }
//
// public String getPersianCategory() { return PersianCategory; }
//
// public void setPersianCategory(String PersianCategory) { this.PersianCategory = PersianCategory; }
//
// public String getTitle() { return Title; }
//
// public void setTitle(String Title) { this.Title = Title; }
//
// public String getBody() { return Body; }
// public void setBody(String Body) { this.Body = Body; }
//
// @Override
// public String toString() {
// return String.format("Document:\n\tID:\t%s\n\tNumber:\t%s\n\tOriginalFile:\t%s\n\tIssue:\t%s\n\tWesternDate:\t%s\n\tPersianDate:\t%s\n\tEnglishCategory:\t%s\n\tPersianCategory:\t%s\n\tTitle:\t%s\n\tBody:\t%s",
// ID,
// Number,
// OriginalFile,
// Issue,
// WesternDate,
// PersianDate,
// EnglishCategory,
// PersianCategory,
// Title,
// Body);
// }
// }
//
// Path: JHazm/src/main/java/jhazm/utility/RegexPattern.java
// public class RegexPattern {
// private final String Pattern;
// private final String Replace;
// public RegexPattern(String pattern, String replace) {
// this.Pattern = pattern;
// this.Replace = replace;
// }
//
// public String apply(String text) {
// return text.replaceAll(Pattern, Replace);
// }
// }
| import com.infomancers.collections.yield.Yielder;
import jhazm.model.Document;
import jhazm.utility.RegexPattern;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; | package jhazm.reader;
/**
* interfaces Hamshahri Corpus (http://ece.ut.ac.ir/dbrg/hamshahri/files/HAM2/Corpus.zip)
* that you must download and extract it.
*
* @author Mojtaba Khallash
*/
public class HamshahriReader {
private final String[] invalidFiles = new String[] {
"hamshahri.dtd", "HAM2-960622.xml", "HAM2-960630.xml", "HAM2-960701.xml", "HAM2-960709.xml",
"HAM2-960710.xml", "HAM2-960711.xml", "HAM2-960817.xml", "HAM2-960818.xml", "HAM2-960819.xml",
"HAM2-960820.xml", "HAM2-961019.xml", "HAM2-961112.xml", "HAM2-961113.xml", "HAM2-961114.xml",
"HAM2-970414.xml", "HAM2-970415.xml", "HAM2-970612.xml", "HAM2-970614.xml", "HAM2-970710.xml",
"HAM2-970712.xml", "HAM2-970713.xml", "HAM2-970717.xml", "HAM2-970719.xml", "HAM2-980317.xml",
"HAM2-040820.xml", "HAM2-040824.xml", "HAM2-040825.xml", "HAM2-040901.xml", "HAM2-040917.xml",
"HAM2-040918.xml", "HAM2-040920.xml", "HAM2-041025.xml", "HAM2-041026.xml", "HAM2-041027.xml",
"HAM2-041230.xml", "HAM2-041231.xml", "HAM2-050101.xml", "HAM2-050102.xml", "HAM2-050223.xml",
"HAM2-050224.xml", "HAM2-050406.xml", "HAM2-050407.xml", "HAM2-050416.xml"
}; | // Path: JHazm/src/main/java/jhazm/model/Document.java
// public class Document {
// private String ID;
// private String Number;
// private String OriginalFile;
// private String Issue;
// private String WesternDate;
// private String PersianDate;
// private String EnglishCategory;
// private String PersianCategory;
// private String Title;
// private String Body;
//
// public String getID() { return ID; }
//
// public void setID(String ID) { this.ID = ID; }
//
// public String getNumber() { return Number; }
//
// public void setNumber(String Number) { this.Number = Number; }
//
// public String getOriginalFile() { return OriginalFile; }
//
// public void setOriginalFile(String OriginalFile) { this.OriginalFile = OriginalFile; }
//
// public String getIssue() { return Issue; }
//
// public void setIssue(String Issue) { this.Issue = Issue; }
//
// public String getWesternDate() { return WesternDate; }
//
// public void setWesternDate(String WesternDate) { this.WesternDate = WesternDate; }
//
// public String getPersianDate() { return PersianDate; }
//
// public void setPersianDate(String PersianDate) { this.PersianDate = PersianDate; }
//
// public String getEnglishCategory() { return EnglishCategory; }
//
// public void setEnglishCategory(String EnglishCategory) { this.EnglishCategory = EnglishCategory; }
//
// public String getPersianCategory() { return PersianCategory; }
//
// public void setPersianCategory(String PersianCategory) { this.PersianCategory = PersianCategory; }
//
// public String getTitle() { return Title; }
//
// public void setTitle(String Title) { this.Title = Title; }
//
// public String getBody() { return Body; }
// public void setBody(String Body) { this.Body = Body; }
//
// @Override
// public String toString() {
// return String.format("Document:\n\tID:\t%s\n\tNumber:\t%s\n\tOriginalFile:\t%s\n\tIssue:\t%s\n\tWesternDate:\t%s\n\tPersianDate:\t%s\n\tEnglishCategory:\t%s\n\tPersianCategory:\t%s\n\tTitle:\t%s\n\tBody:\t%s",
// ID,
// Number,
// OriginalFile,
// Issue,
// WesternDate,
// PersianDate,
// EnglishCategory,
// PersianCategory,
// Title,
// Body);
// }
// }
//
// Path: JHazm/src/main/java/jhazm/utility/RegexPattern.java
// public class RegexPattern {
// private final String Pattern;
// private final String Replace;
// public RegexPattern(String pattern, String replace) {
// this.Pattern = pattern;
// this.Replace = replace;
// }
//
// public String apply(String text) {
// return text.replaceAll(Pattern, Replace);
// }
// }
// Path: JHazm/src/main/java/jhazm/reader/HamshahriReader.java
import com.infomancers.collections.yield.Yielder;
import jhazm.model.Document;
import jhazm.utility.RegexPattern;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
package jhazm.reader;
/**
* interfaces Hamshahri Corpus (http://ece.ut.ac.ir/dbrg/hamshahri/files/HAM2/Corpus.zip)
* that you must download and extract it.
*
* @author Mojtaba Khallash
*/
public class HamshahriReader {
private final String[] invalidFiles = new String[] {
"hamshahri.dtd", "HAM2-960622.xml", "HAM2-960630.xml", "HAM2-960701.xml", "HAM2-960709.xml",
"HAM2-960710.xml", "HAM2-960711.xml", "HAM2-960817.xml", "HAM2-960818.xml", "HAM2-960819.xml",
"HAM2-960820.xml", "HAM2-961019.xml", "HAM2-961112.xml", "HAM2-961113.xml", "HAM2-961114.xml",
"HAM2-970414.xml", "HAM2-970415.xml", "HAM2-970612.xml", "HAM2-970614.xml", "HAM2-970710.xml",
"HAM2-970712.xml", "HAM2-970713.xml", "HAM2-970717.xml", "HAM2-970719.xml", "HAM2-980317.xml",
"HAM2-040820.xml", "HAM2-040824.xml", "HAM2-040825.xml", "HAM2-040901.xml", "HAM2-040917.xml",
"HAM2-040918.xml", "HAM2-040920.xml", "HAM2-041025.xml", "HAM2-041026.xml", "HAM2-041027.xml",
"HAM2-041230.xml", "HAM2-041231.xml", "HAM2-050101.xml", "HAM2-050102.xml", "HAM2-050223.xml",
"HAM2-050224.xml", "HAM2-050406.xml", "HAM2-050407.xml", "HAM2-050416.xml"
}; | private RegexPattern paragraphPattern; |
mojtaba-khallash/JHazm | JHazm/src/main/java/jhazm/reader/HamshahriReader.java | // Path: JHazm/src/main/java/jhazm/model/Document.java
// public class Document {
// private String ID;
// private String Number;
// private String OriginalFile;
// private String Issue;
// private String WesternDate;
// private String PersianDate;
// private String EnglishCategory;
// private String PersianCategory;
// private String Title;
// private String Body;
//
// public String getID() { return ID; }
//
// public void setID(String ID) { this.ID = ID; }
//
// public String getNumber() { return Number; }
//
// public void setNumber(String Number) { this.Number = Number; }
//
// public String getOriginalFile() { return OriginalFile; }
//
// public void setOriginalFile(String OriginalFile) { this.OriginalFile = OriginalFile; }
//
// public String getIssue() { return Issue; }
//
// public void setIssue(String Issue) { this.Issue = Issue; }
//
// public String getWesternDate() { return WesternDate; }
//
// public void setWesternDate(String WesternDate) { this.WesternDate = WesternDate; }
//
// public String getPersianDate() { return PersianDate; }
//
// public void setPersianDate(String PersianDate) { this.PersianDate = PersianDate; }
//
// public String getEnglishCategory() { return EnglishCategory; }
//
// public void setEnglishCategory(String EnglishCategory) { this.EnglishCategory = EnglishCategory; }
//
// public String getPersianCategory() { return PersianCategory; }
//
// public void setPersianCategory(String PersianCategory) { this.PersianCategory = PersianCategory; }
//
// public String getTitle() { return Title; }
//
// public void setTitle(String Title) { this.Title = Title; }
//
// public String getBody() { return Body; }
// public void setBody(String Body) { this.Body = Body; }
//
// @Override
// public String toString() {
// return String.format("Document:\n\tID:\t%s\n\tNumber:\t%s\n\tOriginalFile:\t%s\n\tIssue:\t%s\n\tWesternDate:\t%s\n\tPersianDate:\t%s\n\tEnglishCategory:\t%s\n\tPersianCategory:\t%s\n\tTitle:\t%s\n\tBody:\t%s",
// ID,
// Number,
// OriginalFile,
// Issue,
// WesternDate,
// PersianDate,
// EnglishCategory,
// PersianCategory,
// Title,
// Body);
// }
// }
//
// Path: JHazm/src/main/java/jhazm/utility/RegexPattern.java
// public class RegexPattern {
// private final String Pattern;
// private final String Replace;
// public RegexPattern(String pattern, String replace) {
// this.Pattern = pattern;
// this.Replace = replace;
// }
//
// public String apply(String text) {
// return text.replaceAll(Pattern, Replace);
// }
// }
| import com.infomancers.collections.yield.Yielder;
import jhazm.model.Document;
import jhazm.utility.RegexPattern;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; | "HAM2-970414.xml", "HAM2-970415.xml", "HAM2-970612.xml", "HAM2-970614.xml", "HAM2-970710.xml",
"HAM2-970712.xml", "HAM2-970713.xml", "HAM2-970717.xml", "HAM2-970719.xml", "HAM2-980317.xml",
"HAM2-040820.xml", "HAM2-040824.xml", "HAM2-040825.xml", "HAM2-040901.xml", "HAM2-040917.xml",
"HAM2-040918.xml", "HAM2-040920.xml", "HAM2-041025.xml", "HAM2-041026.xml", "HAM2-041027.xml",
"HAM2-041230.xml", "HAM2-041231.xml", "HAM2-050101.xml", "HAM2-050102.xml", "HAM2-050223.xml",
"HAM2-050224.xml", "HAM2-050406.xml", "HAM2-050407.xml", "HAM2-050416.xml"
};
private RegexPattern paragraphPattern;
private String rootFolder;
public HamshahriReader() {
this("resources/corpora/hamshahri");
}
public HamshahriReader(String root) {
this.rootFolder = root;
this.paragraphPattern = new RegexPattern("(\n.{0,50})(?=\n)", "$1\n");
}
public RegexPattern getParagraphPattern() {
return paragraphPattern;
}
public String getRootFolder() {
return rootFolder;
}
public List<String> getInvalidFiles() {
return Arrays.asList(invalidFiles);
}
| // Path: JHazm/src/main/java/jhazm/model/Document.java
// public class Document {
// private String ID;
// private String Number;
// private String OriginalFile;
// private String Issue;
// private String WesternDate;
// private String PersianDate;
// private String EnglishCategory;
// private String PersianCategory;
// private String Title;
// private String Body;
//
// public String getID() { return ID; }
//
// public void setID(String ID) { this.ID = ID; }
//
// public String getNumber() { return Number; }
//
// public void setNumber(String Number) { this.Number = Number; }
//
// public String getOriginalFile() { return OriginalFile; }
//
// public void setOriginalFile(String OriginalFile) { this.OriginalFile = OriginalFile; }
//
// public String getIssue() { return Issue; }
//
// public void setIssue(String Issue) { this.Issue = Issue; }
//
// public String getWesternDate() { return WesternDate; }
//
// public void setWesternDate(String WesternDate) { this.WesternDate = WesternDate; }
//
// public String getPersianDate() { return PersianDate; }
//
// public void setPersianDate(String PersianDate) { this.PersianDate = PersianDate; }
//
// public String getEnglishCategory() { return EnglishCategory; }
//
// public void setEnglishCategory(String EnglishCategory) { this.EnglishCategory = EnglishCategory; }
//
// public String getPersianCategory() { return PersianCategory; }
//
// public void setPersianCategory(String PersianCategory) { this.PersianCategory = PersianCategory; }
//
// public String getTitle() { return Title; }
//
// public void setTitle(String Title) { this.Title = Title; }
//
// public String getBody() { return Body; }
// public void setBody(String Body) { this.Body = Body; }
//
// @Override
// public String toString() {
// return String.format("Document:\n\tID:\t%s\n\tNumber:\t%s\n\tOriginalFile:\t%s\n\tIssue:\t%s\n\tWesternDate:\t%s\n\tPersianDate:\t%s\n\tEnglishCategory:\t%s\n\tPersianCategory:\t%s\n\tTitle:\t%s\n\tBody:\t%s",
// ID,
// Number,
// OriginalFile,
// Issue,
// WesternDate,
// PersianDate,
// EnglishCategory,
// PersianCategory,
// Title,
// Body);
// }
// }
//
// Path: JHazm/src/main/java/jhazm/utility/RegexPattern.java
// public class RegexPattern {
// private final String Pattern;
// private final String Replace;
// public RegexPattern(String pattern, String replace) {
// this.Pattern = pattern;
// this.Replace = replace;
// }
//
// public String apply(String text) {
// return text.replaceAll(Pattern, Replace);
// }
// }
// Path: JHazm/src/main/java/jhazm/reader/HamshahriReader.java
import com.infomancers.collections.yield.Yielder;
import jhazm.model.Document;
import jhazm.utility.RegexPattern;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
"HAM2-970414.xml", "HAM2-970415.xml", "HAM2-970612.xml", "HAM2-970614.xml", "HAM2-970710.xml",
"HAM2-970712.xml", "HAM2-970713.xml", "HAM2-970717.xml", "HAM2-970719.xml", "HAM2-980317.xml",
"HAM2-040820.xml", "HAM2-040824.xml", "HAM2-040825.xml", "HAM2-040901.xml", "HAM2-040917.xml",
"HAM2-040918.xml", "HAM2-040920.xml", "HAM2-041025.xml", "HAM2-041026.xml", "HAM2-041027.xml",
"HAM2-041230.xml", "HAM2-041231.xml", "HAM2-050101.xml", "HAM2-050102.xml", "HAM2-050223.xml",
"HAM2-050224.xml", "HAM2-050406.xml", "HAM2-050407.xml", "HAM2-050416.xml"
};
private RegexPattern paragraphPattern;
private String rootFolder;
public HamshahriReader() {
this("resources/corpora/hamshahri");
}
public HamshahriReader(String root) {
this.rootFolder = root;
this.paragraphPattern = new RegexPattern("(\n.{0,50})(?=\n)", "$1\n");
}
public RegexPattern getParagraphPattern() {
return paragraphPattern;
}
public String getRootFolder() {
return rootFolder;
}
public List<String> getInvalidFiles() {
return Arrays.asList(invalidFiles);
}
| public Iterable<Document> getDocuments() { |
mojtaba-khallash/JHazm | JHazm/src/test/java/jhazm/test/reader/VerbValencyReaderTest.java | // Path: JHazm/src/main/java/jhazm/model/Verb.java
// public class Verb {
// public String PastLightVerb;
// public String PresentLightVerb;
// public String Prefix;
// public String NonVerbalElement;
// public String Preposition;
// public String Valency;
//
// public Verb(String PastLightVerb, String PresentLightVerb, String Prefix,
// String NonVerbalElement, String Preposition, String Valency) {
// this.PastLightVerb = PastLightVerb;
// this.PresentLightVerb = PresentLightVerb;
// this.Prefix = Prefix;
// this.NonVerbalElement = NonVerbalElement;
// this.Preposition = Preposition;
// this.Valency = Valency;
// }
// }
//
// Path: JHazm/src/main/java/jhazm/reader/VerbValencyReader.java
// public class VerbValencyReader {
// //
// // Fields
// //
//
// private String valencyFile;
//
//
//
// //
// // Constructors
// //
//
// public VerbValencyReader() {
// this("resources/corpora/valency.txt");
// }
//
// public VerbValencyReader(String valencyFile) {
// this.valencyFile = valencyFile;
// }
//
//
//
//
// //
// // API
// //
//
// public Iterable<Verb> getVerbs() throws IOException { return new YieldVernValency(); }
//
//
//
//
// //
// // Helper
// //
//
// private String getValencyFile() {
// return this.valencyFile;
// }
//
// class YieldVernValency extends Yielder<Verb> {
// private BufferedReader br;
//
// public YieldVernValency() {
// try {
// FileInputStream fstream = new FileInputStream(getValencyFile());
// DataInputStream in = new DataInputStream(fstream);
// br = new BufferedReader(new InputStreamReader(in, Charset.forName("UTF8")));
// }
// catch (Exception ex) {
// ex.printStackTrace();
// }
// }
//
// @Override
// protected void yieldNextCore() {
// try {
// String line;
//
// while ((line = br.readLine()) != null) {
// if (line.contains("بن ماضی"))
// continue;
//
// line = line.trim().replace("-\t", "\t");
// String[] parts = line.split("\t");
// if (parts.length == 6) {
// yieldReturn(new Verb(
// parts[0], // PastLightVerb
// parts[1], // PresentLightVerb
// parts[2], // Prefix
// parts[3], // NonVerbalElement
// parts[4], // Preposition
// parts[5])); // Valency
// return;
// }
// }
// br.close();
// }
// catch (Exception ex) {
// ex.printStackTrace();
// }
// }
// }
// }
| import jhazm.model.Verb;
import jhazm.reader.VerbValencyReader;
import org.junit.Test;
import java.io.IOException;
import java.util.Iterator;
import static org.junit.Assert.assertEquals; | package jhazm.test.reader;
/**
* Created by Mojtaba on 30/10/2015.
*/
public class VerbValencyReaderTest {
@Test
public void getVerbsTest() throws IOException { | // Path: JHazm/src/main/java/jhazm/model/Verb.java
// public class Verb {
// public String PastLightVerb;
// public String PresentLightVerb;
// public String Prefix;
// public String NonVerbalElement;
// public String Preposition;
// public String Valency;
//
// public Verb(String PastLightVerb, String PresentLightVerb, String Prefix,
// String NonVerbalElement, String Preposition, String Valency) {
// this.PastLightVerb = PastLightVerb;
// this.PresentLightVerb = PresentLightVerb;
// this.Prefix = Prefix;
// this.NonVerbalElement = NonVerbalElement;
// this.Preposition = Preposition;
// this.Valency = Valency;
// }
// }
//
// Path: JHazm/src/main/java/jhazm/reader/VerbValencyReader.java
// public class VerbValencyReader {
// //
// // Fields
// //
//
// private String valencyFile;
//
//
//
// //
// // Constructors
// //
//
// public VerbValencyReader() {
// this("resources/corpora/valency.txt");
// }
//
// public VerbValencyReader(String valencyFile) {
// this.valencyFile = valencyFile;
// }
//
//
//
//
// //
// // API
// //
//
// public Iterable<Verb> getVerbs() throws IOException { return new YieldVernValency(); }
//
//
//
//
// //
// // Helper
// //
//
// private String getValencyFile() {
// return this.valencyFile;
// }
//
// class YieldVernValency extends Yielder<Verb> {
// private BufferedReader br;
//
// public YieldVernValency() {
// try {
// FileInputStream fstream = new FileInputStream(getValencyFile());
// DataInputStream in = new DataInputStream(fstream);
// br = new BufferedReader(new InputStreamReader(in, Charset.forName("UTF8")));
// }
// catch (Exception ex) {
// ex.printStackTrace();
// }
// }
//
// @Override
// protected void yieldNextCore() {
// try {
// String line;
//
// while ((line = br.readLine()) != null) {
// if (line.contains("بن ماضی"))
// continue;
//
// line = line.trim().replace("-\t", "\t");
// String[] parts = line.split("\t");
// if (parts.length == 6) {
// yieldReturn(new Verb(
// parts[0], // PastLightVerb
// parts[1], // PresentLightVerb
// parts[2], // Prefix
// parts[3], // NonVerbalElement
// parts[4], // Preposition
// parts[5])); // Valency
// return;
// }
// }
// br.close();
// }
// catch (Exception ex) {
// ex.printStackTrace();
// }
// }
// }
// }
// Path: JHazm/src/test/java/jhazm/test/reader/VerbValencyReaderTest.java
import jhazm.model.Verb;
import jhazm.reader.VerbValencyReader;
import org.junit.Test;
import java.io.IOException;
import java.util.Iterator;
import static org.junit.Assert.assertEquals;
package jhazm.test.reader;
/**
* Created by Mojtaba on 30/10/2015.
*/
public class VerbValencyReaderTest {
@Test
public void getVerbsTest() throws IOException { | VerbValencyReader vv = new VerbValencyReader(); |
mojtaba-khallash/JHazm | JHazm/src/test/java/jhazm/test/reader/VerbValencyReaderTest.java | // Path: JHazm/src/main/java/jhazm/model/Verb.java
// public class Verb {
// public String PastLightVerb;
// public String PresentLightVerb;
// public String Prefix;
// public String NonVerbalElement;
// public String Preposition;
// public String Valency;
//
// public Verb(String PastLightVerb, String PresentLightVerb, String Prefix,
// String NonVerbalElement, String Preposition, String Valency) {
// this.PastLightVerb = PastLightVerb;
// this.PresentLightVerb = PresentLightVerb;
// this.Prefix = Prefix;
// this.NonVerbalElement = NonVerbalElement;
// this.Preposition = Preposition;
// this.Valency = Valency;
// }
// }
//
// Path: JHazm/src/main/java/jhazm/reader/VerbValencyReader.java
// public class VerbValencyReader {
// //
// // Fields
// //
//
// private String valencyFile;
//
//
//
// //
// // Constructors
// //
//
// public VerbValencyReader() {
// this("resources/corpora/valency.txt");
// }
//
// public VerbValencyReader(String valencyFile) {
// this.valencyFile = valencyFile;
// }
//
//
//
//
// //
// // API
// //
//
// public Iterable<Verb> getVerbs() throws IOException { return new YieldVernValency(); }
//
//
//
//
// //
// // Helper
// //
//
// private String getValencyFile() {
// return this.valencyFile;
// }
//
// class YieldVernValency extends Yielder<Verb> {
// private BufferedReader br;
//
// public YieldVernValency() {
// try {
// FileInputStream fstream = new FileInputStream(getValencyFile());
// DataInputStream in = new DataInputStream(fstream);
// br = new BufferedReader(new InputStreamReader(in, Charset.forName("UTF8")));
// }
// catch (Exception ex) {
// ex.printStackTrace();
// }
// }
//
// @Override
// protected void yieldNextCore() {
// try {
// String line;
//
// while ((line = br.readLine()) != null) {
// if (line.contains("بن ماضی"))
// continue;
//
// line = line.trim().replace("-\t", "\t");
// String[] parts = line.split("\t");
// if (parts.length == 6) {
// yieldReturn(new Verb(
// parts[0], // PastLightVerb
// parts[1], // PresentLightVerb
// parts[2], // Prefix
// parts[3], // NonVerbalElement
// parts[4], // Preposition
// parts[5])); // Valency
// return;
// }
// }
// br.close();
// }
// catch (Exception ex) {
// ex.printStackTrace();
// }
// }
// }
// }
| import jhazm.model.Verb;
import jhazm.reader.VerbValencyReader;
import org.junit.Test;
import java.io.IOException;
import java.util.Iterator;
import static org.junit.Assert.assertEquals; | package jhazm.test.reader;
/**
* Created by Mojtaba on 30/10/2015.
*/
public class VerbValencyReaderTest {
@Test
public void getVerbsTest() throws IOException {
VerbValencyReader vv = new VerbValencyReader();
String expected = "بر"; | // Path: JHazm/src/main/java/jhazm/model/Verb.java
// public class Verb {
// public String PastLightVerb;
// public String PresentLightVerb;
// public String Prefix;
// public String NonVerbalElement;
// public String Preposition;
// public String Valency;
//
// public Verb(String PastLightVerb, String PresentLightVerb, String Prefix,
// String NonVerbalElement, String Preposition, String Valency) {
// this.PastLightVerb = PastLightVerb;
// this.PresentLightVerb = PresentLightVerb;
// this.Prefix = Prefix;
// this.NonVerbalElement = NonVerbalElement;
// this.Preposition = Preposition;
// this.Valency = Valency;
// }
// }
//
// Path: JHazm/src/main/java/jhazm/reader/VerbValencyReader.java
// public class VerbValencyReader {
// //
// // Fields
// //
//
// private String valencyFile;
//
//
//
// //
// // Constructors
// //
//
// public VerbValencyReader() {
// this("resources/corpora/valency.txt");
// }
//
// public VerbValencyReader(String valencyFile) {
// this.valencyFile = valencyFile;
// }
//
//
//
//
// //
// // API
// //
//
// public Iterable<Verb> getVerbs() throws IOException { return new YieldVernValency(); }
//
//
//
//
// //
// // Helper
// //
//
// private String getValencyFile() {
// return this.valencyFile;
// }
//
// class YieldVernValency extends Yielder<Verb> {
// private BufferedReader br;
//
// public YieldVernValency() {
// try {
// FileInputStream fstream = new FileInputStream(getValencyFile());
// DataInputStream in = new DataInputStream(fstream);
// br = new BufferedReader(new InputStreamReader(in, Charset.forName("UTF8")));
// }
// catch (Exception ex) {
// ex.printStackTrace();
// }
// }
//
// @Override
// protected void yieldNextCore() {
// try {
// String line;
//
// while ((line = br.readLine()) != null) {
// if (line.contains("بن ماضی"))
// continue;
//
// line = line.trim().replace("-\t", "\t");
// String[] parts = line.split("\t");
// if (parts.length == 6) {
// yieldReturn(new Verb(
// parts[0], // PastLightVerb
// parts[1], // PresentLightVerb
// parts[2], // Prefix
// parts[3], // NonVerbalElement
// parts[4], // Preposition
// parts[5])); // Valency
// return;
// }
// }
// br.close();
// }
// catch (Exception ex) {
// ex.printStackTrace();
// }
// }
// }
// }
// Path: JHazm/src/test/java/jhazm/test/reader/VerbValencyReaderTest.java
import jhazm.model.Verb;
import jhazm.reader.VerbValencyReader;
import org.junit.Test;
import java.io.IOException;
import java.util.Iterator;
import static org.junit.Assert.assertEquals;
package jhazm.test.reader;
/**
* Created by Mojtaba on 30/10/2015.
*/
public class VerbValencyReaderTest {
@Test
public void getVerbsTest() throws IOException {
VerbValencyReader vv = new VerbValencyReader();
String expected = "بر"; | Iterator<Verb> iter = vv.getVerbs().iterator(); |
zohmg/zohmg | src/darling/src/java/fm/last/darling/hbase/HBaseUtils.java | // Path: src/darling/src/java/fm/last/darling/utils/Util.java
// public class Util {
//
// public static String epochtoYMD(long epoch) {
// Calendar thence = new GregorianCalendar();
// thence.setTimeInMillis(epoch * 1000);
// int year = thence.get(Calendar.YEAR);
// int month = thence.get(Calendar.MONTH) + 1;
// int day = thence.get(Calendar.DAY_OF_MONTH);
// return String.format("%04d%02d%02d", year, month, day);
// }
//
// public static List<List<Dimension>> readRequestedProjections(File yamlFile) throws FileNotFoundException {
//
// List<List<Dimension>> result = new ArrayList<List<Dimension>>();
//
// // open file, read yaml, turn into pumpkin.
// Map<String, ?> yaml = (Map) Yaml.load(yamlFile);
//
// List<String> projections = (List<String>) yaml.get("projections");
// if(projections == null || projections.isEmpty()) {
// return result;
// }
//
// for (String projectionName : projections) {
// String[] dimensionNames = projectionName.split("-");
// List<Dimension> dimensions = new ArrayList<Dimension>();
//
// for (String dimension : dimensionNames) {
// dimensions.add(new Dimension(dimension));
// }
//
// result.add(dimensions);
// }
//
// return result;
// }
// }
| import fm.last.darling.utils.Util; | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package fm.last.darling.hbase;
public class HBaseUtils {
// totally non-customizable rowkey formatter.
public static byte[] formatRowkey(String unit, long epoch) { | // Path: src/darling/src/java/fm/last/darling/utils/Util.java
// public class Util {
//
// public static String epochtoYMD(long epoch) {
// Calendar thence = new GregorianCalendar();
// thence.setTimeInMillis(epoch * 1000);
// int year = thence.get(Calendar.YEAR);
// int month = thence.get(Calendar.MONTH) + 1;
// int day = thence.get(Calendar.DAY_OF_MONTH);
// return String.format("%04d%02d%02d", year, month, day);
// }
//
// public static List<List<Dimension>> readRequestedProjections(File yamlFile) throws FileNotFoundException {
//
// List<List<Dimension>> result = new ArrayList<List<Dimension>>();
//
// // open file, read yaml, turn into pumpkin.
// Map<String, ?> yaml = (Map) Yaml.load(yamlFile);
//
// List<String> projections = (List<String>) yaml.get("projections");
// if(projections == null || projections.isEmpty()) {
// return result;
// }
//
// for (String projectionName : projections) {
// String[] dimensionNames = projectionName.split("-");
// List<Dimension> dimensions = new ArrayList<Dimension>();
//
// for (String dimension : dimensionNames) {
// dimensions.add(new Dimension(dimension));
// }
//
// result.add(dimensions);
// }
//
// return result;
// }
// }
// Path: src/darling/src/java/fm/last/darling/hbase/HBaseUtils.java
import fm.last.darling.utils.Util;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package fm.last.darling.hbase;
public class HBaseUtils {
// totally non-customizable rowkey formatter.
public static byte[] formatRowkey(String unit, long epoch) { | String ymd = Util.epochtoYMD(epoch); |
zohmg/zohmg | src/darling/test/java/fm/last/darling/util/UtilTest.java | // Path: src/darling/src/java/fm/last/darling/nspace/Dimension.java
// public class Dimension {
// private String dimension;
//
// public Dimension(String dimension) {
// this.dimension = dimension;
// }
//
// public String toString() {
// return dimension;
// }
// }
//
// Path: src/darling/src/java/fm/last/darling/utils/Util.java
// public class Util {
//
// public static String epochtoYMD(long epoch) {
// Calendar thence = new GregorianCalendar();
// thence.setTimeInMillis(epoch * 1000);
// int year = thence.get(Calendar.YEAR);
// int month = thence.get(Calendar.MONTH) + 1;
// int day = thence.get(Calendar.DAY_OF_MONTH);
// return String.format("%04d%02d%02d", year, month, day);
// }
//
// public static List<List<Dimension>> readRequestedProjections(File yamlFile) throws FileNotFoundException {
//
// List<List<Dimension>> result = new ArrayList<List<Dimension>>();
//
// // open file, read yaml, turn into pumpkin.
// Map<String, ?> yaml = (Map) Yaml.load(yamlFile);
//
// List<String> projections = (List<String>) yaml.get("projections");
// if(projections == null || projections.isEmpty()) {
// return result;
// }
//
// for (String projectionName : projections) {
// String[] dimensionNames = projectionName.split("-");
// List<Dimension> dimensions = new ArrayList<Dimension>();
//
// for (String dimension : dimensionNames) {
// dimensions.add(new Dimension(dimension));
// }
//
// result.add(dimensions);
// }
//
// return result;
// }
// }
| import static org.junit.Assert.assertEquals;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
import fm.last.darling.nspace.Dimension;
import fm.last.darling.utils.Util; | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package fm.last.darling.util;
public class UtilTest {
@Test
public void testEpochtoYMD() {
String expected = "20090421"; | // Path: src/darling/src/java/fm/last/darling/nspace/Dimension.java
// public class Dimension {
// private String dimension;
//
// public Dimension(String dimension) {
// this.dimension = dimension;
// }
//
// public String toString() {
// return dimension;
// }
// }
//
// Path: src/darling/src/java/fm/last/darling/utils/Util.java
// public class Util {
//
// public static String epochtoYMD(long epoch) {
// Calendar thence = new GregorianCalendar();
// thence.setTimeInMillis(epoch * 1000);
// int year = thence.get(Calendar.YEAR);
// int month = thence.get(Calendar.MONTH) + 1;
// int day = thence.get(Calendar.DAY_OF_MONTH);
// return String.format("%04d%02d%02d", year, month, day);
// }
//
// public static List<List<Dimension>> readRequestedProjections(File yamlFile) throws FileNotFoundException {
//
// List<List<Dimension>> result = new ArrayList<List<Dimension>>();
//
// // open file, read yaml, turn into pumpkin.
// Map<String, ?> yaml = (Map) Yaml.load(yamlFile);
//
// List<String> projections = (List<String>) yaml.get("projections");
// if(projections == null || projections.isEmpty()) {
// return result;
// }
//
// for (String projectionName : projections) {
// String[] dimensionNames = projectionName.split("-");
// List<Dimension> dimensions = new ArrayList<Dimension>();
//
// for (String dimension : dimensionNames) {
// dimensions.add(new Dimension(dimension));
// }
//
// result.add(dimensions);
// }
//
// return result;
// }
// }
// Path: src/darling/test/java/fm/last/darling/util/UtilTest.java
import static org.junit.Assert.assertEquals;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
import fm.last.darling.nspace.Dimension;
import fm.last.darling.utils.Util;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package fm.last.darling.util;
public class UtilTest {
@Test
public void testEpochtoYMD() {
String expected = "20090421"; | String ymd = Util.epochtoYMD(1240300000); |
zohmg/zohmg | src/darling/test/java/fm/last/darling/util/UtilTest.java | // Path: src/darling/src/java/fm/last/darling/nspace/Dimension.java
// public class Dimension {
// private String dimension;
//
// public Dimension(String dimension) {
// this.dimension = dimension;
// }
//
// public String toString() {
// return dimension;
// }
// }
//
// Path: src/darling/src/java/fm/last/darling/utils/Util.java
// public class Util {
//
// public static String epochtoYMD(long epoch) {
// Calendar thence = new GregorianCalendar();
// thence.setTimeInMillis(epoch * 1000);
// int year = thence.get(Calendar.YEAR);
// int month = thence.get(Calendar.MONTH) + 1;
// int day = thence.get(Calendar.DAY_OF_MONTH);
// return String.format("%04d%02d%02d", year, month, day);
// }
//
// public static List<List<Dimension>> readRequestedProjections(File yamlFile) throws FileNotFoundException {
//
// List<List<Dimension>> result = new ArrayList<List<Dimension>>();
//
// // open file, read yaml, turn into pumpkin.
// Map<String, ?> yaml = (Map) Yaml.load(yamlFile);
//
// List<String> projections = (List<String>) yaml.get("projections");
// if(projections == null || projections.isEmpty()) {
// return result;
// }
//
// for (String projectionName : projections) {
// String[] dimensionNames = projectionName.split("-");
// List<Dimension> dimensions = new ArrayList<Dimension>();
//
// for (String dimension : dimensionNames) {
// dimensions.add(new Dimension(dimension));
// }
//
// result.add(dimensions);
// }
//
// return result;
// }
// }
| import static org.junit.Assert.assertEquals;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
import fm.last.darling.nspace.Dimension;
import fm.last.darling.utils.Util; | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package fm.last.darling.util;
public class UtilTest {
@Test
public void testEpochtoYMD() {
String expected = "20090421";
String ymd = Util.epochtoYMD(1240300000);
assertEquals(ymd, expected);
}
@Test
public void testreadRequestedProjections() throws FileNotFoundException {
File testDataFolder = new File("src/darling/test/data");
File yaml = new File(testDataFolder, "dataset.yaml"); | // Path: src/darling/src/java/fm/last/darling/nspace/Dimension.java
// public class Dimension {
// private String dimension;
//
// public Dimension(String dimension) {
// this.dimension = dimension;
// }
//
// public String toString() {
// return dimension;
// }
// }
//
// Path: src/darling/src/java/fm/last/darling/utils/Util.java
// public class Util {
//
// public static String epochtoYMD(long epoch) {
// Calendar thence = new GregorianCalendar();
// thence.setTimeInMillis(epoch * 1000);
// int year = thence.get(Calendar.YEAR);
// int month = thence.get(Calendar.MONTH) + 1;
// int day = thence.get(Calendar.DAY_OF_MONTH);
// return String.format("%04d%02d%02d", year, month, day);
// }
//
// public static List<List<Dimension>> readRequestedProjections(File yamlFile) throws FileNotFoundException {
//
// List<List<Dimension>> result = new ArrayList<List<Dimension>>();
//
// // open file, read yaml, turn into pumpkin.
// Map<String, ?> yaml = (Map) Yaml.load(yamlFile);
//
// List<String> projections = (List<String>) yaml.get("projections");
// if(projections == null || projections.isEmpty()) {
// return result;
// }
//
// for (String projectionName : projections) {
// String[] dimensionNames = projectionName.split("-");
// List<Dimension> dimensions = new ArrayList<Dimension>();
//
// for (String dimension : dimensionNames) {
// dimensions.add(new Dimension(dimension));
// }
//
// result.add(dimensions);
// }
//
// return result;
// }
// }
// Path: src/darling/test/java/fm/last/darling/util/UtilTest.java
import static org.junit.Assert.assertEquals;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
import fm.last.darling.nspace.Dimension;
import fm.last.darling.utils.Util;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package fm.last.darling.util;
public class UtilTest {
@Test
public void testEpochtoYMD() {
String expected = "20090421";
String ymd = Util.epochtoYMD(1240300000);
assertEquals(ymd, expected);
}
@Test
public void testreadRequestedProjections() throws FileNotFoundException {
File testDataFolder = new File("src/darling/test/data");
File yaml = new File(testDataFolder, "dataset.yaml"); | List<List<Dimension>> ret = Util.readRequestedProjections(yaml); |
zohmg/zohmg | src/darling/src/java/fm/last/darling/utils/Util.java | // Path: src/darling/src/java/fm/last/darling/nspace/Dimension.java
// public class Dimension {
// private String dimension;
//
// public Dimension(String dimension) {
// this.dimension = dimension;
// }
//
// public String toString() {
// return dimension;
// }
// }
| import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Map;
import org.ho.yaml.Yaml;
import fm.last.darling.nspace.Dimension; | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package fm.last.darling.utils;
public class Util {
public static String epochtoYMD(long epoch) {
Calendar thence = new GregorianCalendar();
thence.setTimeInMillis(epoch * 1000);
int year = thence.get(Calendar.YEAR);
int month = thence.get(Calendar.MONTH) + 1;
int day = thence.get(Calendar.DAY_OF_MONTH);
return String.format("%04d%02d%02d", year, month, day);
}
| // Path: src/darling/src/java/fm/last/darling/nspace/Dimension.java
// public class Dimension {
// private String dimension;
//
// public Dimension(String dimension) {
// this.dimension = dimension;
// }
//
// public String toString() {
// return dimension;
// }
// }
// Path: src/darling/src/java/fm/last/darling/utils/Util.java
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Map;
import org.ho.yaml.Yaml;
import fm.last.darling.nspace.Dimension;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package fm.last.darling.utils;
public class Util {
public static String epochtoYMD(long epoch) {
Calendar thence = new GregorianCalendar();
thence.setTimeInMillis(epoch * 1000);
int year = thence.get(Calendar.YEAR);
int month = thence.get(Calendar.MONTH) + 1;
int day = thence.get(Calendar.DAY_OF_MONTH);
return String.format("%04d%02d%02d", year, month, day);
}
| public static List<List<Dimension>> readRequestedProjections(File yamlFile) throws FileNotFoundException { |
zohmg/zohmg | src/darling/test/java/fm/last/darling/hbase/HBaseJSONOutputReaderTest.java | // Path: src/darling/src/java/fm/last/darling/hbase/HBaseJSONOutputReader.java
// public class HBaseJSONOutputReader extends OutputReader<ImmutableBytesWritable, Put> {
//
// private ImmutableBytesWritable rowkey;
// private Put put;
//
// // save the last seen line of output as Text
// // and the bytes, so that getLastOutput can recreate it as a string.
// private Text line;
// private byte[] bytes;
//
// private DataInput datainput;
// private Configuration conf;
// private int numKeyFields;
// private byte[] separator;
//
// private LineReader lineReader;
//
// @Override
// public void initialize(PipeMapRed pipeMapRed) throws IOException {
// super.initialize(pipeMapRed);
//
// rowkey = new ImmutableBytesWritable();
// line = new Text();
//
// datainput = pipeMapRed.getClientInput();
// conf = pipeMapRed.getConfiguration();
// numKeyFields = pipeMapRed.getNumOfKeyFields();
// separator = pipeMapRed.getFieldSeparator();
//
// lineReader = new LineReader((InputStream) datainput, conf);
// }
//
// @Override
// public boolean readKeyValue() throws IOException {
// if (lineReader.readLine(line) <= 0)
// return false;
// bytes = line.getBytes();
// interpretKeyandValue(bytes, line.getLength());
// line.clear();
// return true;
// }
//
// // split a UTF-8 line into key and value
// // lifted from from org.apache.hadoop.streaming.io.TextOutputReader
// private void interpretKeyandValue(byte[] line, int length) throws IOException {
// // Need to find numKeyFields separators
// int pos = UTF8ByteArrayUtils.findBytes(line, 0, length, separator);
// for (int k = 1; k < numKeyFields && pos != -1; k++) {
// pos = UTF8ByteArrayUtils.findBytes(line, pos + separator.length, length, separator);
// }
//
// Text k = new Text();
// Text v = new Text();
// try {
// if (pos == -1) {
// k.set(line, 0, length);
// v.set("");
// } else {
// StreamKeyValUtil.splitKeyVal(line, 0, length, k, v, pos, separator.length);
// }
// } catch (CharacterCodingException e) {
// throw new IOException(e);
// }
//
// // removing a ' at the start and end of the key
// byte[] keyBytes = trimOuterBytes(k);
//
// rowkey = new ImmutableBytesWritable(keyBytes);
// put = new Put(keyBytes);
//
// String tmpV = v.toString();
// String json = tmpV.substring(1, tmpV.length() - 1);
// Map<String, Map> payload;
// try {
// payload = (Map<String, Map>) ObjectBuilder.fromJSON(json); // the 'erased' type?
// } catch (Exception e) {
// throw new IOException("error, fromJson: ", e);
// }
//
// Set<Map.Entry<String, Map>> entries = payload.entrySet();
// for (Map.Entry<String, Map> entry : entries) {
// String cfq = entry.getKey(); // let's consider not joining family and qualifier at emitter.
// String[] parts = cfq.split(":");
// if (parts.length < 2)
// continue;
// String family = parts[0];
// String qualifier = parts[1];
//
// Map dict = entry.getValue(); // unchecked.
//
// // expecting dict to carry 'value',
// Object value = dict.get("value");
// if (value == null)
// continue; // no good.
//
// // ..and possibly 'timestamp'.
// //Object ts = 0;
// //if (dict.containsKey("timestamp"))
// //ts = dict.get("timestamp");
//
// put.add(family.getBytes("UTF-8"), qualifier.getBytes("UTF-8"), value.toString().getBytes("UTF-8"));
// }
// }
//
// private byte[] trimOuterBytes(Text text) {
// byte[] bytes = new byte[text.getLength() - 2];
// System.arraycopy(text.getBytes(), 1, bytes, 0, bytes.length);
// return bytes;
// }
//
// @Override
// public ImmutableBytesWritable getCurrentKey() throws IOException {
// return rowkey;
// }
//
// @Override
// public Put getCurrentValue() throws IOException {
// return put;
// }
//
// @Override
// public String getLastOutput() {
// try {
// return new String(bytes, "UTF-8");
// } catch (UnsupportedEncodingException e) {
// return "<undecodable>";
// }
// }
// }
| import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.io.ByteArrayInputStream;
import java.io.DataInput;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import org.apache.hadoop.hbase.io.BatchUpdate;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.mapred.JobConf;
import org.apache.hadoop.streaming.PipeReducer;
import org.junit.Test;
import fm.last.darling.hbase.HBaseJSONOutputReader; | package fm.last.darling.hbase;
public class HBaseJSONOutputReaderTest {
String keyString1 = "pageviews-20080717";
String column1 = "country-domain-useragent-usertype:all-m.last.fm-other-all";
String keyString2 = "pageviews-20090101";
String column2 = "country:all";
@Test
public void test() throws IOException {
PipeReducer pipeReducer = new MockPipeReducer();
pipeReducer.configure(new JobConf());
| // Path: src/darling/src/java/fm/last/darling/hbase/HBaseJSONOutputReader.java
// public class HBaseJSONOutputReader extends OutputReader<ImmutableBytesWritable, Put> {
//
// private ImmutableBytesWritable rowkey;
// private Put put;
//
// // save the last seen line of output as Text
// // and the bytes, so that getLastOutput can recreate it as a string.
// private Text line;
// private byte[] bytes;
//
// private DataInput datainput;
// private Configuration conf;
// private int numKeyFields;
// private byte[] separator;
//
// private LineReader lineReader;
//
// @Override
// public void initialize(PipeMapRed pipeMapRed) throws IOException {
// super.initialize(pipeMapRed);
//
// rowkey = new ImmutableBytesWritable();
// line = new Text();
//
// datainput = pipeMapRed.getClientInput();
// conf = pipeMapRed.getConfiguration();
// numKeyFields = pipeMapRed.getNumOfKeyFields();
// separator = pipeMapRed.getFieldSeparator();
//
// lineReader = new LineReader((InputStream) datainput, conf);
// }
//
// @Override
// public boolean readKeyValue() throws IOException {
// if (lineReader.readLine(line) <= 0)
// return false;
// bytes = line.getBytes();
// interpretKeyandValue(bytes, line.getLength());
// line.clear();
// return true;
// }
//
// // split a UTF-8 line into key and value
// // lifted from from org.apache.hadoop.streaming.io.TextOutputReader
// private void interpretKeyandValue(byte[] line, int length) throws IOException {
// // Need to find numKeyFields separators
// int pos = UTF8ByteArrayUtils.findBytes(line, 0, length, separator);
// for (int k = 1; k < numKeyFields && pos != -1; k++) {
// pos = UTF8ByteArrayUtils.findBytes(line, pos + separator.length, length, separator);
// }
//
// Text k = new Text();
// Text v = new Text();
// try {
// if (pos == -1) {
// k.set(line, 0, length);
// v.set("");
// } else {
// StreamKeyValUtil.splitKeyVal(line, 0, length, k, v, pos, separator.length);
// }
// } catch (CharacterCodingException e) {
// throw new IOException(e);
// }
//
// // removing a ' at the start and end of the key
// byte[] keyBytes = trimOuterBytes(k);
//
// rowkey = new ImmutableBytesWritable(keyBytes);
// put = new Put(keyBytes);
//
// String tmpV = v.toString();
// String json = tmpV.substring(1, tmpV.length() - 1);
// Map<String, Map> payload;
// try {
// payload = (Map<String, Map>) ObjectBuilder.fromJSON(json); // the 'erased' type?
// } catch (Exception e) {
// throw new IOException("error, fromJson: ", e);
// }
//
// Set<Map.Entry<String, Map>> entries = payload.entrySet();
// for (Map.Entry<String, Map> entry : entries) {
// String cfq = entry.getKey(); // let's consider not joining family and qualifier at emitter.
// String[] parts = cfq.split(":");
// if (parts.length < 2)
// continue;
// String family = parts[0];
// String qualifier = parts[1];
//
// Map dict = entry.getValue(); // unchecked.
//
// // expecting dict to carry 'value',
// Object value = dict.get("value");
// if (value == null)
// continue; // no good.
//
// // ..and possibly 'timestamp'.
// //Object ts = 0;
// //if (dict.containsKey("timestamp"))
// //ts = dict.get("timestamp");
//
// put.add(family.getBytes("UTF-8"), qualifier.getBytes("UTF-8"), value.toString().getBytes("UTF-8"));
// }
// }
//
// private byte[] trimOuterBytes(Text text) {
// byte[] bytes = new byte[text.getLength() - 2];
// System.arraycopy(text.getBytes(), 1, bytes, 0, bytes.length);
// return bytes;
// }
//
// @Override
// public ImmutableBytesWritable getCurrentKey() throws IOException {
// return rowkey;
// }
//
// @Override
// public Put getCurrentValue() throws IOException {
// return put;
// }
//
// @Override
// public String getLastOutput() {
// try {
// return new String(bytes, "UTF-8");
// } catch (UnsupportedEncodingException e) {
// return "<undecodable>";
// }
// }
// }
// Path: src/darling/test/java/fm/last/darling/hbase/HBaseJSONOutputReaderTest.java
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.io.ByteArrayInputStream;
import java.io.DataInput;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import org.apache.hadoop.hbase.io.BatchUpdate;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.mapred.JobConf;
import org.apache.hadoop.streaming.PipeReducer;
import org.junit.Test;
import fm.last.darling.hbase.HBaseJSONOutputReader;
package fm.last.darling.hbase;
public class HBaseJSONOutputReaderTest {
String keyString1 = "pageviews-20080717";
String column1 = "country-domain-useragent-usertype:all-m.last.fm-other-all";
String keyString2 = "pageviews-20090101";
String column2 = "country:all";
@Test
public void test() throws IOException {
PipeReducer pipeReducer = new MockPipeReducer();
pipeReducer.configure(new JobConf());
| HBaseJSONOutputReader outputReader = new HBaseJSONOutputReader(); |
plutext/docx4j-export-FO | src/docx4j-extras/PdfViaIText/org/docx4j/convert/out/pdf/viaIText/Conversion.java | // Path: src/main/java/org/docx4j/convert/out/pdf/viaXSLFO/PdfSettings.java
// public class PdfSettings extends FOSettings {
// }
| import java.io.IOException;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.xml.bind.JAXBElement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.docx4j.XmlUtils;
import org.docx4j.convert.out.pdf.viaXSLFO.PdfSettings;
import org.docx4j.dml.wordprocessingDrawing.Inline;
import org.docx4j.fonts.Mapper;
import org.docx4j.fonts.PhysicalFont;
import org.docx4j.fonts.PhysicalFonts;
import org.docx4j.model.structure.HeaderFooterPolicy;
import org.docx4j.openpackaging.exceptions.Docx4JException;
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
import org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage;
import org.docx4j.wml.Body;
import org.docx4j.wml.Ftr;
import org.docx4j.wml.Hdr;
import org.docx4j.wml.RFonts;
import org.docx4j.wml.RPr;
import com.lowagie.text.Chunk;
import com.lowagie.text.Document;
import com.lowagie.text.ExceptionConverter;
import com.lowagie.text.Font;
import com.lowagie.text.Image;
import com.lowagie.text.PageSize;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfPageEventHelper;
import com.lowagie.text.pdf.PdfWriter; | package org.docx4j.convert.out.pdf.viaIText;
public class Conversion extends org.docx4j.convert.out.pdf.PdfConversion {
protected static Logger log = LoggerFactory.getLogger(Conversion.class);
public Conversion(WordprocessingMLPackage wordMLPackage) {
super(wordMLPackage);
headerFooterPolicy = wordMLPackage.getHeaderFooterPolicy();
}
// iText style modifiers
// see core.lowagie.text.pdf.BaseFont
public final static String BOLD = ",Bold";
public final static String ITALIC = ",Italic";
public final static String BOLD_ITALIC = ",BoldItalic";
public final static int DEFAULT_FONT_SIZE=11;
Map<String, BaseFont> baseFonts = new HashMap<String, BaseFont>();
HeaderFooterPolicy headerFooterPolicy;
Document pdfDoc;
/** Create a pdf version of the document, using XSL FO.
*
* @param os
* The OutputStream to write the pdf to
*
* */
@Override | // Path: src/main/java/org/docx4j/convert/out/pdf/viaXSLFO/PdfSettings.java
// public class PdfSettings extends FOSettings {
// }
// Path: src/docx4j-extras/PdfViaIText/org/docx4j/convert/out/pdf/viaIText/Conversion.java
import java.io.IOException;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.xml.bind.JAXBElement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.docx4j.XmlUtils;
import org.docx4j.convert.out.pdf.viaXSLFO.PdfSettings;
import org.docx4j.dml.wordprocessingDrawing.Inline;
import org.docx4j.fonts.Mapper;
import org.docx4j.fonts.PhysicalFont;
import org.docx4j.fonts.PhysicalFonts;
import org.docx4j.model.structure.HeaderFooterPolicy;
import org.docx4j.openpackaging.exceptions.Docx4JException;
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
import org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage;
import org.docx4j.wml.Body;
import org.docx4j.wml.Ftr;
import org.docx4j.wml.Hdr;
import org.docx4j.wml.RFonts;
import org.docx4j.wml.RPr;
import com.lowagie.text.Chunk;
import com.lowagie.text.Document;
import com.lowagie.text.ExceptionConverter;
import com.lowagie.text.Font;
import com.lowagie.text.Image;
import com.lowagie.text.PageSize;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfPageEventHelper;
import com.lowagie.text.pdf.PdfWriter;
package org.docx4j.convert.out.pdf.viaIText;
public class Conversion extends org.docx4j.convert.out.pdf.PdfConversion {
protected static Logger log = LoggerFactory.getLogger(Conversion.class);
public Conversion(WordprocessingMLPackage wordMLPackage) {
super(wordMLPackage);
headerFooterPolicy = wordMLPackage.getHeaderFooterPolicy();
}
// iText style modifiers
// see core.lowagie.text.pdf.BaseFont
public final static String BOLD = ",Bold";
public final static String ITALIC = ",Italic";
public final static String BOLD_ITALIC = ",BoldItalic";
public final static int DEFAULT_FONT_SIZE=11;
Map<String, BaseFont> baseFonts = new HashMap<String, BaseFont>();
HeaderFooterPolicy headerFooterPolicy;
Document pdfDoc;
/** Create a pdf version of the document, using XSL FO.
*
* @param os
* The OutputStream to write the pdf to
*
* */
@Override | public void output(OutputStream os, PdfSettings settings) throws Docx4JException { |
plutext/docx4j-export-FO | src/test/java/org/docx4j/convert/out/XSLFO/TextBoxTest.java | // Path: src/main/java/org/docx4j/convert/out/fo/FOExporterVisitor.java
// public class FOExporterVisitor extends AbstractFOExporter {
// protected static final FOExporterVisitorDelegate EXPORTER_DELEGATE_INSTANCE = new
// FOExporterVisitorDelegate();
//
// protected static FOExporterVisitor instance = null;
//
// protected FOExporterVisitor() {
// super(EXPORTER_DELEGATE_INSTANCE);
// }
//
// public static Exporter<FOSettings> getInstance() {
// if (instance == null) {
// synchronized(FOExporterVisitor.class) {
// if (instance == null) {
// instance = new FOExporterVisitor();
// }
// }
// }
// return instance;
// }
//
// }
| import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import javax.xml.bind.JAXBElement;
import org.apache.commons.io.FileUtils;
import org.docx4j.Docx4J;
import org.docx4j.XmlUtils;
import org.docx4j.convert.out.FOSettings;
import org.docx4j.convert.out.common.Exporter;
import org.docx4j.convert.out.fo.FOExporterVisitor;
import org.docx4j.fonts.PhysicalFonts;
import org.docx4j.jaxb.Context;
import org.docx4j.openpackaging.exceptions.Docx4JException;
import org.docx4j.openpackaging.exceptions.InvalidFormatException;
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
import org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart;
import org.docx4j.vml.CTPath;
import org.docx4j.vml.CTShape;
import org.docx4j.vml.CTShapetype;
import org.docx4j.vml.CTStroke;
import org.docx4j.vml.CTTextbox;
import org.docx4j.vml.wordprocessingDrawing.CTWrap;
import org.docx4j.wml.CTTxbxContent;
import org.docx4j.wml.P;
import org.docx4j.wml.Pict;
import org.docx4j.wml.R;
import org.docx4j.wml.Text;
import org.junit.Ignore; |
// style="position:absolute;margin-left:0;margin-top:0;width:186.95pt;height:110.55pt;z-index:251659264;visibility:visible;mso-wrap-style:square;mso-width-percent:400;mso-height-percent:200;mso-left-percent:600;mso-wrap-distance-left:9pt;mso-wrap-distance-top:0;mso-wrap-distance-right:9pt;mso-wrap-distance-bottom:0;mso-position-horizontal-relative:left-margin-area;mso-position-vertical:absolute;mso-position-vertical-relative:text;mso-width-percent:400;mso-height-percent:200;mso-left-percent:600;mso-width-relative:margin;mso-height-relative:margin;v-text-anchor:top"
p.getContent().add( r);
p.getContent().add(addFiller());
return wordMLPackage;
}
private static void execute(WordprocessingMLPackage wordMLPackage) throws Docx4JException, IOException {
// Pretty print the main document part
System.out.println(
XmlUtils.marshaltoString(wordMLPackage.getMainDocumentPart().getJaxbElement(), true, true) );
// Optionally save it
if (save) {
String filename = System.getProperty("user.dir") + "/OUT_CreateWordprocessingMLDocument.docx";
wordMLPackage.save(new File(filename) );
System.out.println("Saved " + filename);
}
// FO
if (fo) {
OutputStream baos = new ByteArrayOutputStream(); | // Path: src/main/java/org/docx4j/convert/out/fo/FOExporterVisitor.java
// public class FOExporterVisitor extends AbstractFOExporter {
// protected static final FOExporterVisitorDelegate EXPORTER_DELEGATE_INSTANCE = new
// FOExporterVisitorDelegate();
//
// protected static FOExporterVisitor instance = null;
//
// protected FOExporterVisitor() {
// super(EXPORTER_DELEGATE_INSTANCE);
// }
//
// public static Exporter<FOSettings> getInstance() {
// if (instance == null) {
// synchronized(FOExporterVisitor.class) {
// if (instance == null) {
// instance = new FOExporterVisitor();
// }
// }
// }
// return instance;
// }
//
// }
// Path: src/test/java/org/docx4j/convert/out/XSLFO/TextBoxTest.java
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import javax.xml.bind.JAXBElement;
import org.apache.commons.io.FileUtils;
import org.docx4j.Docx4J;
import org.docx4j.XmlUtils;
import org.docx4j.convert.out.FOSettings;
import org.docx4j.convert.out.common.Exporter;
import org.docx4j.convert.out.fo.FOExporterVisitor;
import org.docx4j.fonts.PhysicalFonts;
import org.docx4j.jaxb.Context;
import org.docx4j.openpackaging.exceptions.Docx4JException;
import org.docx4j.openpackaging.exceptions.InvalidFormatException;
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
import org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart;
import org.docx4j.vml.CTPath;
import org.docx4j.vml.CTShape;
import org.docx4j.vml.CTShapetype;
import org.docx4j.vml.CTStroke;
import org.docx4j.vml.CTTextbox;
import org.docx4j.vml.wordprocessingDrawing.CTWrap;
import org.docx4j.wml.CTTxbxContent;
import org.docx4j.wml.P;
import org.docx4j.wml.Pict;
import org.docx4j.wml.R;
import org.docx4j.wml.Text;
import org.junit.Ignore;
// style="position:absolute;margin-left:0;margin-top:0;width:186.95pt;height:110.55pt;z-index:251659264;visibility:visible;mso-wrap-style:square;mso-width-percent:400;mso-height-percent:200;mso-left-percent:600;mso-wrap-distance-left:9pt;mso-wrap-distance-top:0;mso-wrap-distance-right:9pt;mso-wrap-distance-bottom:0;mso-position-horizontal-relative:left-margin-area;mso-position-vertical:absolute;mso-position-vertical-relative:text;mso-width-percent:400;mso-height-percent:200;mso-left-percent:600;mso-width-relative:margin;mso-height-relative:margin;v-text-anchor:top"
p.getContent().add( r);
p.getContent().add(addFiller());
return wordMLPackage;
}
private static void execute(WordprocessingMLPackage wordMLPackage) throws Docx4JException, IOException {
// Pretty print the main document part
System.out.println(
XmlUtils.marshaltoString(wordMLPackage.getMainDocumentPart().getJaxbElement(), true, true) );
// Optionally save it
if (save) {
String filename = System.getProperty("user.dir") + "/OUT_CreateWordprocessingMLDocument.docx";
wordMLPackage.save(new File(filename) );
System.out.println("Saved " + filename);
}
// FO
if (fo) {
OutputStream baos = new ByteArrayOutputStream(); | Exporter<FOSettings> exporter = FOExporterVisitor.getInstance(); |
plutext/docx4j-export-FO | src/main/java/org/docx4j/convert/out/pdf/PdfConversion.java | // Path: src/main/java/org/docx4j/convert/out/pdf/viaXSLFO/PdfSettings.java
// public class PdfSettings extends FOSettings {
// }
| import org.docx4j.openpackaging.exceptions.Docx4JException;
import java.io.OutputStream;
import org.docx4j.convert.out.pdf.viaXSLFO.PdfSettings; | /*
Licensed to Plutext Pty Ltd under one or more contributor license agreements.
* This file is part of docx4j.
docx4j is licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package org.docx4j.convert.out.pdf;
/**
* There are 3 ways a package can be converted to PDF:
*
* 1. via XSL FO
* 1a - using XSLT to generate the XSL FO
* 1b - using TraversalUtils to generate the XSL FO
*
* 2. via HTML, using docX2HTML.xslt
*
* 3. via iText
*
* Method 1a is the standard way of doing things
* Method 1b is experimental (Dec 2012)
*
* Methods 2 & 3 are in docx4j extras
*
* @author jharrop
* @deprecated
*/
public abstract class PdfConversion {
@Deprecated | // Path: src/main/java/org/docx4j/convert/out/pdf/viaXSLFO/PdfSettings.java
// public class PdfSettings extends FOSettings {
// }
// Path: src/main/java/org/docx4j/convert/out/pdf/PdfConversion.java
import org.docx4j.openpackaging.exceptions.Docx4JException;
import java.io.OutputStream;
import org.docx4j.convert.out.pdf.viaXSLFO.PdfSettings;
/*
Licensed to Plutext Pty Ltd under one or more contributor license agreements.
* This file is part of docx4j.
docx4j is licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package org.docx4j.convert.out.pdf;
/**
* There are 3 ways a package can be converted to PDF:
*
* 1. via XSL FO
* 1a - using XSLT to generate the XSL FO
* 1b - using TraversalUtils to generate the XSL FO
*
* 2. via HTML, using docX2HTML.xslt
*
* 3. via iText
*
* Method 1a is the standard way of doing things
* Method 1b is experimental (Dec 2012)
*
* Methods 2 & 3 are in docx4j extras
*
* @author jharrop
* @deprecated
*/
public abstract class PdfConversion {
@Deprecated | public abstract void outputXSLFO(OutputStream os, PdfSettings settings) throws Docx4JException; |
plutext/docx4j-export-FO | src/main/java/org/docx4j/convert/out/fo/FOPictWriterFloatAvoided.java | // Path: src/main/java/org/docx4j/convert/out/fo/renderers/AbstractFORenderer.java
// public abstract class AbstractFORenderer implements FORenderer {
//
// protected static Logger log = LoggerFactory.getLogger(AbstractFORenderer.class);
//
// // TODO this needs to be rethought in an architectural sense,
// // since PictWriter is here altering the behaviour of
// // downstream renderer, and we don't want that!
// public boolean TEXTBOX_POSTPROCESSING_REQUIRED = false;
//
// static Templates xslt_POSTPROCESSING;
// static {
// try {
// Source xsltSource = new StreamSource(
// org.docx4j.utils.ResourceUtils.getResource(
// "org/docx4j/convert/out/fo/renderers/AbstractFORenderer_POSTPROCESSING.xslt"));
// xslt_POSTPROCESSING = XmlUtils.getTransformerTemplate(xsltSource);
// } catch (IOException e) {
// e.printStackTrace();
// } catch (TransformerConfigurationException e) {
// e.printStackTrace();
// }
//
// }
//
//
// }
| import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import java.util.Map;
import org.docx4j.XmlUtils;
import org.docx4j.convert.out.FORenderer;
import org.docx4j.convert.out.FOSettings;
import org.docx4j.convert.out.common.AbstractWmlConversionContext;
import org.docx4j.convert.out.common.ConversionSectionWrapper;
import org.docx4j.convert.out.fo.renderers.AbstractFORenderer;
import org.docx4j.model.structure.PageDimensions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory; |
</fo:table-cell>
</fo:table-row>
</fo:table-body>
*/
Element tbody = doc.createElementNS(XSL_FO, "table-body");
ret.appendChild(tbody);
Element trow = doc.createElementNS(XSL_FO, "table-row");
tbody.appendChild(trow);
// Cell 1 is the text box
Element tc1 = doc.createElementNS(XSL_FO, "table-cell");
trow.appendChild(tc1);
Element block = doc.createElementNS(XSL_FO, "block");
setBorders(block); // for now, solid borders, so we can see the text box
tc1.appendChild(block);
XmlUtils.treeCopy(childNodes, block);
// Cell 2 is the p content proper (which we don't have)
Element tc2 = doc.createElementNS(XSL_FO, "table-cell");
trow.appendChild(tc2);
// tc2.appendChild(
// doc.createComment("CONTENT GOES HERE"));
Element placeholder = doc.createElementNS(XSL_FO, "block");
placeholder.setTextContent("#TEXTBOX#"); // magic string
tc2.appendChild(placeholder);
// TODO here the architecture needs further thought | // Path: src/main/java/org/docx4j/convert/out/fo/renderers/AbstractFORenderer.java
// public abstract class AbstractFORenderer implements FORenderer {
//
// protected static Logger log = LoggerFactory.getLogger(AbstractFORenderer.class);
//
// // TODO this needs to be rethought in an architectural sense,
// // since PictWriter is here altering the behaviour of
// // downstream renderer, and we don't want that!
// public boolean TEXTBOX_POSTPROCESSING_REQUIRED = false;
//
// static Templates xslt_POSTPROCESSING;
// static {
// try {
// Source xsltSource = new StreamSource(
// org.docx4j.utils.ResourceUtils.getResource(
// "org/docx4j/convert/out/fo/renderers/AbstractFORenderer_POSTPROCESSING.xslt"));
// xslt_POSTPROCESSING = XmlUtils.getTransformerTemplate(xsltSource);
// } catch (IOException e) {
// e.printStackTrace();
// } catch (TransformerConfigurationException e) {
// e.printStackTrace();
// }
//
// }
//
//
// }
// Path: src/main/java/org/docx4j/convert/out/fo/FOPictWriterFloatAvoided.java
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import java.util.Map;
import org.docx4j.XmlUtils;
import org.docx4j.convert.out.FORenderer;
import org.docx4j.convert.out.FOSettings;
import org.docx4j.convert.out.common.AbstractWmlConversionContext;
import org.docx4j.convert.out.common.ConversionSectionWrapper;
import org.docx4j.convert.out.fo.renderers.AbstractFORenderer;
import org.docx4j.model.structure.PageDimensions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
</fo:table-cell>
</fo:table-row>
</fo:table-body>
*/
Element tbody = doc.createElementNS(XSL_FO, "table-body");
ret.appendChild(tbody);
Element trow = doc.createElementNS(XSL_FO, "table-row");
tbody.appendChild(trow);
// Cell 1 is the text box
Element tc1 = doc.createElementNS(XSL_FO, "table-cell");
trow.appendChild(tc1);
Element block = doc.createElementNS(XSL_FO, "block");
setBorders(block); // for now, solid borders, so we can see the text box
tc1.appendChild(block);
XmlUtils.treeCopy(childNodes, block);
// Cell 2 is the p content proper (which we don't have)
Element tc2 = doc.createElementNS(XSL_FO, "table-cell");
trow.appendChild(tc2);
// tc2.appendChild(
// doc.createComment("CONTENT GOES HERE"));
Element placeholder = doc.createElementNS(XSL_FO, "block");
placeholder.setTextContent("#TEXTBOX#"); // magic string
tc2.appendChild(placeholder);
// TODO here the architecture needs further thought | if (foRenderer instanceof AbstractFORenderer) { |
plutext/docx4j-export-FO | src/samples/docx4j/org/docx4j/samples/FONonXSLT.java | // Path: src/main/java/org/docx4j/convert/out/XSLFO/XSLFOExporterNonXSLT.java
// public class XSLFOExporterNonXSLT {
// private static Logger log = LoggerFactory.getLogger(XSLFOExporterNonXSLT.class);
// protected static final int DEFAULT_OUTPUT_SIZE = 102400;
//
// FOSettings foSettings = null;
//
// public XSLFOExporterNonXSLT(WordprocessingMLPackage wmlPackage,
// FOSettings pdfSettings) {
//
// foSettings = pdfSettings;
// if ((foSettings.getWmlPackage() == null) && (wmlPackage != null)) {
// foSettings.setWmlPackage(wmlPackage);
// }
// }
//
// /**
// * Generate XSL FO for the entire MainDocumentPart.
// * @return
// */
// public org.w3c.dom.Document export() throws Docx4JException {
// ByteArrayOutputStream outStream = new ByteArrayOutputStream(DEFAULT_OUTPUT_SIZE);
// Document ret = null;
// foSettings.setApacheFopMime(FOSettings.INTERNAL_FO_MIME);
// try {
// Docx4J.toFO(foSettings, outStream, Docx4J.FLAG_EXPORT_PREFER_NONXSL);
// ret = XmlUtils.getNewDocumentBuilder().parse(new ByteArrayInputStream(outStream.toByteArray()));
// } catch (Docx4JException e) {
// log.error("Exception exporting document: " + e.getMessage(), e);
// } catch (SAXException e) {
// log.error("Exception parsing document: " + e.getMessage(), e);
// } catch (IOException e) {
// log.error("Exception parsing document: " + e.getMessage(), e);
// }
// return ret;
// }
//
//
// // ========================================================================
// public void output(Document xslfo, OutputStream os, Configuration fopConfigZZZ) throws Docx4JException {
// FORenderer renderer = FORendererApacheFOP.getInstance();
// String foDocument = XmlUtils.w3CDomNodeToString(xslfo);
// renderer.render(foDocument, foSettings, false, null, os);
// }
// }
| import java.io.OutputStream;
import org.docx4j.XmlUtils;
import org.docx4j.convert.out.FOSettings;
import org.docx4j.convert.out.XSLFO.XSLFOExporterNonXSLT;
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
import org.w3c.dom.Document; | /*
* Copyright 2012, Plutext Pty Ltd.
*
* This file is part of docx4j.
docx4j is licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package org.docx4j.samples;
/**
*
* Running Xalan extension functions on Android is problematic:
*
* http://stackoverflow.com/questions/10579339/is-it-possible-to-call-a-java-extension-function-from-xalan-on-android
*
* and generating the XSL FO via Xalan + extension functions
* is a bit slow,
* so this uses TraversalUtils to generate XSL FO output
* without any need for Xalan or XSLT.
*
*/
public class FONonXSLT {
/**
* @param args
*/
public static void main(String[] args) throws Exception {
String inputfilepath;
String outputfilepath;
inputfilepath = System.getProperty("user.dir")
// + "/hlink.docx";
// + "/OpenXML_1ed_Part4.docx";
// + "/sample-docs/word/sample-docx.docx";
// + "/sample-docs/word/2003/word2003-vml.docx";
// + "/table-nested.docx";
// + "/sample-docs/word/headers.docx";
+ "/sample-docs/word/sample-docxv2.docx";
WordprocessingMLPackage wmlPackage = WordprocessingMLPackage
.load(new java.io.File(inputfilepath));
FOSettings pdfSettings = new FOSettings();
pdfSettings.setWmlPackage(wmlPackage);
| // Path: src/main/java/org/docx4j/convert/out/XSLFO/XSLFOExporterNonXSLT.java
// public class XSLFOExporterNonXSLT {
// private static Logger log = LoggerFactory.getLogger(XSLFOExporterNonXSLT.class);
// protected static final int DEFAULT_OUTPUT_SIZE = 102400;
//
// FOSettings foSettings = null;
//
// public XSLFOExporterNonXSLT(WordprocessingMLPackage wmlPackage,
// FOSettings pdfSettings) {
//
// foSettings = pdfSettings;
// if ((foSettings.getWmlPackage() == null) && (wmlPackage != null)) {
// foSettings.setWmlPackage(wmlPackage);
// }
// }
//
// /**
// * Generate XSL FO for the entire MainDocumentPart.
// * @return
// */
// public org.w3c.dom.Document export() throws Docx4JException {
// ByteArrayOutputStream outStream = new ByteArrayOutputStream(DEFAULT_OUTPUT_SIZE);
// Document ret = null;
// foSettings.setApacheFopMime(FOSettings.INTERNAL_FO_MIME);
// try {
// Docx4J.toFO(foSettings, outStream, Docx4J.FLAG_EXPORT_PREFER_NONXSL);
// ret = XmlUtils.getNewDocumentBuilder().parse(new ByteArrayInputStream(outStream.toByteArray()));
// } catch (Docx4JException e) {
// log.error("Exception exporting document: " + e.getMessage(), e);
// } catch (SAXException e) {
// log.error("Exception parsing document: " + e.getMessage(), e);
// } catch (IOException e) {
// log.error("Exception parsing document: " + e.getMessage(), e);
// }
// return ret;
// }
//
//
// // ========================================================================
// public void output(Document xslfo, OutputStream os, Configuration fopConfigZZZ) throws Docx4JException {
// FORenderer renderer = FORendererApacheFOP.getInstance();
// String foDocument = XmlUtils.w3CDomNodeToString(xslfo);
// renderer.render(foDocument, foSettings, false, null, os);
// }
// }
// Path: src/samples/docx4j/org/docx4j/samples/FONonXSLT.java
import java.io.OutputStream;
import org.docx4j.XmlUtils;
import org.docx4j.convert.out.FOSettings;
import org.docx4j.convert.out.XSLFO.XSLFOExporterNonXSLT;
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
import org.w3c.dom.Document;
/*
* Copyright 2012, Plutext Pty Ltd.
*
* This file is part of docx4j.
docx4j is licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package org.docx4j.samples;
/**
*
* Running Xalan extension functions on Android is problematic:
*
* http://stackoverflow.com/questions/10579339/is-it-possible-to-call-a-java-extension-function-from-xalan-on-android
*
* and generating the XSL FO via Xalan + extension functions
* is a bit slow,
* so this uses TraversalUtils to generate XSL FO output
* without any need for Xalan or XSLT.
*
*/
public class FONonXSLT {
/**
* @param args
*/
public static void main(String[] args) throws Exception {
String inputfilepath;
String outputfilepath;
inputfilepath = System.getProperty("user.dir")
// + "/hlink.docx";
// + "/OpenXML_1ed_Part4.docx";
// + "/sample-docs/word/sample-docx.docx";
// + "/sample-docs/word/2003/word2003-vml.docx";
// + "/table-nested.docx";
// + "/sample-docs/word/headers.docx";
+ "/sample-docs/word/sample-docxv2.docx";
WordprocessingMLPackage wmlPackage = WordprocessingMLPackage
.load(new java.io.File(inputfilepath));
FOSettings pdfSettings = new FOSettings();
pdfSettings.setWmlPackage(wmlPackage);
| XSLFOExporterNonXSLT withoutXSLT = new XSLFOExporterNonXSLT(wmlPackage, |
codeforkjeff/conciliator | src/main/java/com/codefork/refine/SearchQueryFactory.java | // Path: src/main/java/com/codefork/refine/resources/NameType.java
// public class NameType {
//
// private String id;
// private String name;
//
// public NameType(String id, String name) {
// this.id = id;
// this.name = name;
// }
//
// public String getId() {
// return id;
// }
//
// public void setId(String id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// @Override
// public boolean equals(Object obj) {
// if(obj instanceof NameType) {
// NameType obj2 = (NameType) obj;
// return obj2.getId().equals(getId())
// && obj2.getName().equals(getName());
// }
// return false;
// }
// }
| import com.codefork.refine.resources.NameType;
import com.fasterxml.jackson.databind.JsonNode; | package com.codefork.refine;
public interface SearchQueryFactory {
SearchQuery createSearchQuery(JsonNode queryStruct);
| // Path: src/main/java/com/codefork/refine/resources/NameType.java
// public class NameType {
//
// private String id;
// private String name;
//
// public NameType(String id, String name) {
// this.id = id;
// this.name = name;
// }
//
// public String getId() {
// return id;
// }
//
// public void setId(String id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// @Override
// public boolean equals(Object obj) {
// if(obj instanceof NameType) {
// NameType obj2 = (NameType) obj;
// return obj2.getId().equals(getId())
// && obj2.getName().equals(getName());
// }
// return false;
// }
// }
// Path: src/main/java/com/codefork/refine/SearchQueryFactory.java
import com.codefork.refine.resources.NameType;
import com.fasterxml.jackson.databind.JsonNode;
package com.codefork.refine;
public interface SearchQueryFactory {
SearchQuery createSearchQuery(JsonNode queryStruct);
| SearchQuery createSearchQuery(String query, int limit, NameType nameType, String typeStrict); |
codeforkjeff/conciliator | src/main/java/com/codefork/refine/solr/SolrParseState.java | // Path: src/main/java/com/codefork/refine/parsers/ParseState.java
// public class ParseState {
//
// public boolean captureChars = false;
//
// public final List<Result> results = new ArrayList<>();
// public Result result = null;
//
// /** buffer for collecting contents of an Element as parser does processing */
// public StringBuilder buf = new StringBuilder();
//
// }
//
// Path: src/main/java/com/codefork/refine/resources/NameType.java
// public class NameType {
//
// private String id;
// private String name;
//
// public NameType(String id, String name) {
// this.id = id;
// this.name = name;
// }
//
// public String getId() {
// return id;
// }
//
// public void setId(String id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// @Override
// public boolean equals(Object obj) {
// if(obj instanceof NameType) {
// NameType obj2 = (NameType) obj;
// return obj2.getId().equals(getId())
// && obj2.getName().equals(getName());
// }
// return false;
// }
// }
| import com.codefork.refine.parsers.ParseState;
import com.codefork.refine.resources.NameType;
import java.util.ArrayList;
import java.util.List; | package com.codefork.refine.solr;
public class SolrParseState extends ParseState {
enum Field { ID, NAME }
Field fieldBeingCaptured;
List<String> multipleValues = new ArrayList<>();
// we don't yet support multiple name types for Solr records
// so this is the list we use for every result. | // Path: src/main/java/com/codefork/refine/parsers/ParseState.java
// public class ParseState {
//
// public boolean captureChars = false;
//
// public final List<Result> results = new ArrayList<>();
// public Result result = null;
//
// /** buffer for collecting contents of an Element as parser does processing */
// public StringBuilder buf = new StringBuilder();
//
// }
//
// Path: src/main/java/com/codefork/refine/resources/NameType.java
// public class NameType {
//
// private String id;
// private String name;
//
// public NameType(String id, String name) {
// this.id = id;
// this.name = name;
// }
//
// public String getId() {
// return id;
// }
//
// public void setId(String id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// @Override
// public boolean equals(Object obj) {
// if(obj instanceof NameType) {
// NameType obj2 = (NameType) obj;
// return obj2.getId().equals(getId())
// && obj2.getName().equals(getName());
// }
// return false;
// }
// }
// Path: src/main/java/com/codefork/refine/solr/SolrParseState.java
import com.codefork.refine.parsers.ParseState;
import com.codefork.refine.resources.NameType;
import java.util.ArrayList;
import java.util.List;
package com.codefork.refine.solr;
public class SolrParseState extends ParseState {
enum Field { ID, NAME }
Field fieldBeingCaptured;
List<String> multipleValues = new ArrayList<>();
// we don't yet support multiple name types for Solr records
// so this is the list we use for every result. | List<NameType> nameTypes = new ArrayList<>(); |
codeforkjeff/conciliator | src/main/java/com/codefork/refine/viaf/VIAFMetaDataResponse.java | // Path: src/main/java/com/codefork/refine/resources/NameType.java
// public class NameType {
//
// private String id;
// private String name;
//
// public NameType(String id, String name) {
// this.id = id;
// this.name = name;
// }
//
// public String getId() {
// return id;
// }
//
// public void setId(String id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// @Override
// public boolean equals(Object obj) {
// if(obj instanceof NameType) {
// NameType obj2 = (NameType) obj;
// return obj2.getId().equals(getId())
// && obj2.getName().equals(getName());
// }
// return false;
// }
// }
//
// Path: src/main/java/com/codefork/refine/resources/ServiceMetaDataResponse.java
// @JsonInclude(JsonInclude.Include.NON_NULL)
// public abstract class ServiceMetaDataResponse {
//
// private String name;
// private String identifierSpace;
// private String schemaSpace;
// private View view;
// private List<NameType> defaultTypes;
// private Preview preview;
// private Extend extend;
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public String getIdentifierSpace() {
// return identifierSpace;
// }
//
// public void setIdentifierSpace(String identifierSpace) {
// this.identifierSpace = identifierSpace;
// }
//
// public String getSchemaSpace() {
// return schemaSpace;
// }
//
// public void setSchemaSpace(String schemaSpace) {
// this.schemaSpace = schemaSpace;
// }
//
// public View getView() {
// return view;
// }
//
// public void setView(View view) {
// this.view = view;
// }
//
// public List<NameType> getDefaultTypes() {
// return defaultTypes;
// }
//
// public void setDefaultTypes(List<NameType> defaultTypes) {
// this.defaultTypes = defaultTypes;
// }
//
// public Preview getPreview() {
// return preview;
// }
//
// public void setPreview(Preview preview) {
// this.preview = preview;
// }
//
// public Extend getExtend() {
// return extend;
// }
//
// public void setExtend(Extend extend) {
// this.extend = extend;
// }
//
// }
//
// Path: src/main/java/com/codefork/refine/resources/View.java
// public class View {
// private String url;
//
// public View(String url) {
// this.url = url;
// }
//
// public String getUrl() {
// return url;
// }
//
// public void setUrl(String url) {
// this.url = url;
// }
//
// }
| import com.codefork.refine.resources.NameType;
import com.codefork.refine.resources.ServiceMetaDataResponse;
import com.codefork.refine.resources.View;
import java.util.ArrayList;
import java.util.List; | package com.codefork.refine.viaf;
public class VIAFMetaDataResponse extends ServiceMetaDataResponse {
private final static String IDENTIFIER_SPACE = "http://rdf.freebase.com/ns/user/hangy/viaf"; | // Path: src/main/java/com/codefork/refine/resources/NameType.java
// public class NameType {
//
// private String id;
// private String name;
//
// public NameType(String id, String name) {
// this.id = id;
// this.name = name;
// }
//
// public String getId() {
// return id;
// }
//
// public void setId(String id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// @Override
// public boolean equals(Object obj) {
// if(obj instanceof NameType) {
// NameType obj2 = (NameType) obj;
// return obj2.getId().equals(getId())
// && obj2.getName().equals(getName());
// }
// return false;
// }
// }
//
// Path: src/main/java/com/codefork/refine/resources/ServiceMetaDataResponse.java
// @JsonInclude(JsonInclude.Include.NON_NULL)
// public abstract class ServiceMetaDataResponse {
//
// private String name;
// private String identifierSpace;
// private String schemaSpace;
// private View view;
// private List<NameType> defaultTypes;
// private Preview preview;
// private Extend extend;
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public String getIdentifierSpace() {
// return identifierSpace;
// }
//
// public void setIdentifierSpace(String identifierSpace) {
// this.identifierSpace = identifierSpace;
// }
//
// public String getSchemaSpace() {
// return schemaSpace;
// }
//
// public void setSchemaSpace(String schemaSpace) {
// this.schemaSpace = schemaSpace;
// }
//
// public View getView() {
// return view;
// }
//
// public void setView(View view) {
// this.view = view;
// }
//
// public List<NameType> getDefaultTypes() {
// return defaultTypes;
// }
//
// public void setDefaultTypes(List<NameType> defaultTypes) {
// this.defaultTypes = defaultTypes;
// }
//
// public Preview getPreview() {
// return preview;
// }
//
// public void setPreview(Preview preview) {
// this.preview = preview;
// }
//
// public Extend getExtend() {
// return extend;
// }
//
// public void setExtend(Extend extend) {
// this.extend = extend;
// }
//
// }
//
// Path: src/main/java/com/codefork/refine/resources/View.java
// public class View {
// private String url;
//
// public View(String url) {
// this.url = url;
// }
//
// public String getUrl() {
// return url;
// }
//
// public void setUrl(String url) {
// this.url = url;
// }
//
// }
// Path: src/main/java/com/codefork/refine/viaf/VIAFMetaDataResponse.java
import com.codefork.refine.resources.NameType;
import com.codefork.refine.resources.ServiceMetaDataResponse;
import com.codefork.refine.resources.View;
import java.util.ArrayList;
import java.util.List;
package com.codefork.refine.viaf;
public class VIAFMetaDataResponse extends ServiceMetaDataResponse {
private final static String IDENTIFIER_SPACE = "http://rdf.freebase.com/ns/user/hangy/viaf"; | private final static View VIEW = new View("http://viaf.org/viaf/{{id}}"); |
codeforkjeff/conciliator | src/main/java/com/codefork/refine/viaf/VIAFMetaDataResponse.java | // Path: src/main/java/com/codefork/refine/resources/NameType.java
// public class NameType {
//
// private String id;
// private String name;
//
// public NameType(String id, String name) {
// this.id = id;
// this.name = name;
// }
//
// public String getId() {
// return id;
// }
//
// public void setId(String id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// @Override
// public boolean equals(Object obj) {
// if(obj instanceof NameType) {
// NameType obj2 = (NameType) obj;
// return obj2.getId().equals(getId())
// && obj2.getName().equals(getName());
// }
// return false;
// }
// }
//
// Path: src/main/java/com/codefork/refine/resources/ServiceMetaDataResponse.java
// @JsonInclude(JsonInclude.Include.NON_NULL)
// public abstract class ServiceMetaDataResponse {
//
// private String name;
// private String identifierSpace;
// private String schemaSpace;
// private View view;
// private List<NameType> defaultTypes;
// private Preview preview;
// private Extend extend;
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public String getIdentifierSpace() {
// return identifierSpace;
// }
//
// public void setIdentifierSpace(String identifierSpace) {
// this.identifierSpace = identifierSpace;
// }
//
// public String getSchemaSpace() {
// return schemaSpace;
// }
//
// public void setSchemaSpace(String schemaSpace) {
// this.schemaSpace = schemaSpace;
// }
//
// public View getView() {
// return view;
// }
//
// public void setView(View view) {
// this.view = view;
// }
//
// public List<NameType> getDefaultTypes() {
// return defaultTypes;
// }
//
// public void setDefaultTypes(List<NameType> defaultTypes) {
// this.defaultTypes = defaultTypes;
// }
//
// public Preview getPreview() {
// return preview;
// }
//
// public void setPreview(Preview preview) {
// this.preview = preview;
// }
//
// public Extend getExtend() {
// return extend;
// }
//
// public void setExtend(Extend extend) {
// this.extend = extend;
// }
//
// }
//
// Path: src/main/java/com/codefork/refine/resources/View.java
// public class View {
// private String url;
//
// public View(String url) {
// this.url = url;
// }
//
// public String getUrl() {
// return url;
// }
//
// public void setUrl(String url) {
// this.url = url;
// }
//
// }
| import com.codefork.refine.resources.NameType;
import com.codefork.refine.resources.ServiceMetaDataResponse;
import com.codefork.refine.resources.View;
import java.util.ArrayList;
import java.util.List; | package com.codefork.refine.viaf;
public class VIAFMetaDataResponse extends ServiceMetaDataResponse {
private final static String IDENTIFIER_SPACE = "http://rdf.freebase.com/ns/user/hangy/viaf";
private final static View VIEW = new View("http://viaf.org/viaf/{{id}}");
private final static String SCHEMA_SPACE = "http://rdf.freebase.com/ns/type.object.id"; | // Path: src/main/java/com/codefork/refine/resources/NameType.java
// public class NameType {
//
// private String id;
// private String name;
//
// public NameType(String id, String name) {
// this.id = id;
// this.name = name;
// }
//
// public String getId() {
// return id;
// }
//
// public void setId(String id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// @Override
// public boolean equals(Object obj) {
// if(obj instanceof NameType) {
// NameType obj2 = (NameType) obj;
// return obj2.getId().equals(getId())
// && obj2.getName().equals(getName());
// }
// return false;
// }
// }
//
// Path: src/main/java/com/codefork/refine/resources/ServiceMetaDataResponse.java
// @JsonInclude(JsonInclude.Include.NON_NULL)
// public abstract class ServiceMetaDataResponse {
//
// private String name;
// private String identifierSpace;
// private String schemaSpace;
// private View view;
// private List<NameType> defaultTypes;
// private Preview preview;
// private Extend extend;
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public String getIdentifierSpace() {
// return identifierSpace;
// }
//
// public void setIdentifierSpace(String identifierSpace) {
// this.identifierSpace = identifierSpace;
// }
//
// public String getSchemaSpace() {
// return schemaSpace;
// }
//
// public void setSchemaSpace(String schemaSpace) {
// this.schemaSpace = schemaSpace;
// }
//
// public View getView() {
// return view;
// }
//
// public void setView(View view) {
// this.view = view;
// }
//
// public List<NameType> getDefaultTypes() {
// return defaultTypes;
// }
//
// public void setDefaultTypes(List<NameType> defaultTypes) {
// this.defaultTypes = defaultTypes;
// }
//
// public Preview getPreview() {
// return preview;
// }
//
// public void setPreview(Preview preview) {
// this.preview = preview;
// }
//
// public Extend getExtend() {
// return extend;
// }
//
// public void setExtend(Extend extend) {
// this.extend = extend;
// }
//
// }
//
// Path: src/main/java/com/codefork/refine/resources/View.java
// public class View {
// private String url;
//
// public View(String url) {
// this.url = url;
// }
//
// public String getUrl() {
// return url;
// }
//
// public void setUrl(String url) {
// this.url = url;
// }
//
// }
// Path: src/main/java/com/codefork/refine/viaf/VIAFMetaDataResponse.java
import com.codefork.refine.resources.NameType;
import com.codefork.refine.resources.ServiceMetaDataResponse;
import com.codefork.refine.resources.View;
import java.util.ArrayList;
import java.util.List;
package com.codefork.refine.viaf;
public class VIAFMetaDataResponse extends ServiceMetaDataResponse {
private final static String IDENTIFIER_SPACE = "http://rdf.freebase.com/ns/user/hangy/viaf";
private final static View VIEW = new View("http://viaf.org/viaf/{{id}}");
private final static String SCHEMA_SPACE = "http://rdf.freebase.com/ns/type.object.id"; | private final static List<NameType> DEFAULT_TYPES = new ArrayList<>(); |
codeforkjeff/conciliator | src/main/java/com/codefork/refine/parsers/xml/XMLParser.java | // Path: src/main/java/com/codefork/refine/parsers/ParseState.java
// public class ParseState {
//
// public boolean captureChars = false;
//
// public final List<Result> results = new ArrayList<>();
// public Result result = null;
//
// /** buffer for collecting contents of an Element as parser does processing */
// public StringBuilder buf = new StringBuilder();
//
// }
//
// Path: src/main/java/com/codefork/refine/resources/Result.java
// public class Result {
//
// private String id;
// private String name;
//
// /**
// * It's weird that this is a list but that's what OpenRefine expects.
// * A VIAF result only ever has one type, but maybe other reconciliation
// * services return multiple types for a name?
// */
// private List<NameType> type;
// private double score;
// private boolean match;
//
// public Result() {
// }
//
// public Result(String id, String name, NameType nameType, double score, boolean match) {
// this.id = id;
// this.name = name;
// this.type = new ArrayList<>();
// this.type.add(nameType);
// this.score = score;
// this.match = match;
// }
//
// public String getId() {
// return id;
// }
//
// public void setId(String id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public List<NameType> getType() {
// return type;
// }
//
// public void setType(List<NameType> resultType) {
// this.type = resultType;
// }
//
// public double getScore() {
// return score;
// }
//
// public void setScore(double score) {
// this.score = score;
// }
//
// public boolean isMatch() {
// return match;
// }
//
// public void setMatch(boolean match) {
// this.match = match;
// }
//
// }
| import com.codefork.refine.parsers.ParseState;
import com.codefork.refine.resources.Result;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Stack; | package com.codefork.refine.parsers.xml;
/**
* SAX parser handler. We use SAX b/c it's faster than loading a whole DOM.
*/
public abstract class XMLParser<R extends ParseState> extends DefaultHandler {
protected Map<String, StartElementHandler<R>> startElementHandlers = new HashMap<>();
protected Map<String, EndElementHandler<R>> endElementHandlers = new HashMap<>();
public final Stack<String> path = new Stack<>();
protected R parseState;
public XMLParser() {
parseState = createParseState();
}
/**
* XMLParser subclasses should override this if they want to create their
* own ParseState subclasses.
* @return
*/
public abstract R createParseState();
| // Path: src/main/java/com/codefork/refine/parsers/ParseState.java
// public class ParseState {
//
// public boolean captureChars = false;
//
// public final List<Result> results = new ArrayList<>();
// public Result result = null;
//
// /** buffer for collecting contents of an Element as parser does processing */
// public StringBuilder buf = new StringBuilder();
//
// }
//
// Path: src/main/java/com/codefork/refine/resources/Result.java
// public class Result {
//
// private String id;
// private String name;
//
// /**
// * It's weird that this is a list but that's what OpenRefine expects.
// * A VIAF result only ever has one type, but maybe other reconciliation
// * services return multiple types for a name?
// */
// private List<NameType> type;
// private double score;
// private boolean match;
//
// public Result() {
// }
//
// public Result(String id, String name, NameType nameType, double score, boolean match) {
// this.id = id;
// this.name = name;
// this.type = new ArrayList<>();
// this.type.add(nameType);
// this.score = score;
// this.match = match;
// }
//
// public String getId() {
// return id;
// }
//
// public void setId(String id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public List<NameType> getType() {
// return type;
// }
//
// public void setType(List<NameType> resultType) {
// this.type = resultType;
// }
//
// public double getScore() {
// return score;
// }
//
// public void setScore(double score) {
// this.score = score;
// }
//
// public boolean isMatch() {
// return match;
// }
//
// public void setMatch(boolean match) {
// this.match = match;
// }
//
// }
// Path: src/main/java/com/codefork/refine/parsers/xml/XMLParser.java
import com.codefork.refine.parsers.ParseState;
import com.codefork.refine.resources.Result;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Stack;
package com.codefork.refine.parsers.xml;
/**
* SAX parser handler. We use SAX b/c it's faster than loading a whole DOM.
*/
public abstract class XMLParser<R extends ParseState> extends DefaultHandler {
protected Map<String, StartElementHandler<R>> startElementHandlers = new HashMap<>();
protected Map<String, EndElementHandler<R>> endElementHandlers = new HashMap<>();
public final Stack<String> path = new Stack<>();
protected R parseState;
public XMLParser() {
parseState = createParseState();
}
/**
* XMLParser subclasses should override this if they want to create their
* own ParseState subclasses.
* @return
*/
public abstract R createParseState();
| public List<Result> getResults() { |
codeforkjeff/conciliator | src/main/java/com/codefork/refine/openlibrary/OpenLibraryMetaDataResponse.java | // Path: src/main/java/com/codefork/refine/resources/NameType.java
// public class NameType {
//
// private String id;
// private String name;
//
// public NameType(String id, String name) {
// this.id = id;
// this.name = name;
// }
//
// public String getId() {
// return id;
// }
//
// public void setId(String id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// @Override
// public boolean equals(Object obj) {
// if(obj instanceof NameType) {
// NameType obj2 = (NameType) obj;
// return obj2.getId().equals(getId())
// && obj2.getName().equals(getName());
// }
// return false;
// }
// }
//
// Path: src/main/java/com/codefork/refine/resources/ServiceMetaDataResponse.java
// @JsonInclude(JsonInclude.Include.NON_NULL)
// public abstract class ServiceMetaDataResponse {
//
// private String name;
// private String identifierSpace;
// private String schemaSpace;
// private View view;
// private List<NameType> defaultTypes;
// private Preview preview;
// private Extend extend;
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public String getIdentifierSpace() {
// return identifierSpace;
// }
//
// public void setIdentifierSpace(String identifierSpace) {
// this.identifierSpace = identifierSpace;
// }
//
// public String getSchemaSpace() {
// return schemaSpace;
// }
//
// public void setSchemaSpace(String schemaSpace) {
// this.schemaSpace = schemaSpace;
// }
//
// public View getView() {
// return view;
// }
//
// public void setView(View view) {
// this.view = view;
// }
//
// public List<NameType> getDefaultTypes() {
// return defaultTypes;
// }
//
// public void setDefaultTypes(List<NameType> defaultTypes) {
// this.defaultTypes = defaultTypes;
// }
//
// public Preview getPreview() {
// return preview;
// }
//
// public void setPreview(Preview preview) {
// this.preview = preview;
// }
//
// public Extend getExtend() {
// return extend;
// }
//
// public void setExtend(Extend extend) {
// this.extend = extend;
// }
//
// }
//
// Path: src/main/java/com/codefork/refine/resources/View.java
// public class View {
// private String url;
//
// public View(String url) {
// this.url = url;
// }
//
// public String getUrl() {
// return url;
// }
//
// public void setUrl(String url) {
// this.url = url;
// }
//
// }
| import com.codefork.refine.resources.NameType;
import com.codefork.refine.resources.ServiceMetaDataResponse;
import com.codefork.refine.resources.View;
import com.fasterxml.jackson.annotation.JsonInclude;
import java.util.ArrayList;
import java.util.List; | package com.codefork.refine.openlibrary;
@JsonInclude(JsonInclude.Include.NON_NULL)
public class OpenLibraryMetaDataResponse extends ServiceMetaDataResponse {
private final static String IDENTIFIER_SPACE = "http://rdf.freebase.com/ns/user/hangy/viaf"; | // Path: src/main/java/com/codefork/refine/resources/NameType.java
// public class NameType {
//
// private String id;
// private String name;
//
// public NameType(String id, String name) {
// this.id = id;
// this.name = name;
// }
//
// public String getId() {
// return id;
// }
//
// public void setId(String id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// @Override
// public boolean equals(Object obj) {
// if(obj instanceof NameType) {
// NameType obj2 = (NameType) obj;
// return obj2.getId().equals(getId())
// && obj2.getName().equals(getName());
// }
// return false;
// }
// }
//
// Path: src/main/java/com/codefork/refine/resources/ServiceMetaDataResponse.java
// @JsonInclude(JsonInclude.Include.NON_NULL)
// public abstract class ServiceMetaDataResponse {
//
// private String name;
// private String identifierSpace;
// private String schemaSpace;
// private View view;
// private List<NameType> defaultTypes;
// private Preview preview;
// private Extend extend;
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public String getIdentifierSpace() {
// return identifierSpace;
// }
//
// public void setIdentifierSpace(String identifierSpace) {
// this.identifierSpace = identifierSpace;
// }
//
// public String getSchemaSpace() {
// return schemaSpace;
// }
//
// public void setSchemaSpace(String schemaSpace) {
// this.schemaSpace = schemaSpace;
// }
//
// public View getView() {
// return view;
// }
//
// public void setView(View view) {
// this.view = view;
// }
//
// public List<NameType> getDefaultTypes() {
// return defaultTypes;
// }
//
// public void setDefaultTypes(List<NameType> defaultTypes) {
// this.defaultTypes = defaultTypes;
// }
//
// public Preview getPreview() {
// return preview;
// }
//
// public void setPreview(Preview preview) {
// this.preview = preview;
// }
//
// public Extend getExtend() {
// return extend;
// }
//
// public void setExtend(Extend extend) {
// this.extend = extend;
// }
//
// }
//
// Path: src/main/java/com/codefork/refine/resources/View.java
// public class View {
// private String url;
//
// public View(String url) {
// this.url = url;
// }
//
// public String getUrl() {
// return url;
// }
//
// public void setUrl(String url) {
// this.url = url;
// }
//
// }
// Path: src/main/java/com/codefork/refine/openlibrary/OpenLibraryMetaDataResponse.java
import com.codefork.refine.resources.NameType;
import com.codefork.refine.resources.ServiceMetaDataResponse;
import com.codefork.refine.resources.View;
import com.fasterxml.jackson.annotation.JsonInclude;
import java.util.ArrayList;
import java.util.List;
package com.codefork.refine.openlibrary;
@JsonInclude(JsonInclude.Include.NON_NULL)
public class OpenLibraryMetaDataResponse extends ServiceMetaDataResponse {
private final static String IDENTIFIER_SPACE = "http://rdf.freebase.com/ns/user/hangy/viaf"; | private final static View VIEW = new View("https://openlibrary.org{{id}}"); |
codeforkjeff/conciliator | src/main/java/com/codefork/refine/openlibrary/OpenLibraryMetaDataResponse.java | // Path: src/main/java/com/codefork/refine/resources/NameType.java
// public class NameType {
//
// private String id;
// private String name;
//
// public NameType(String id, String name) {
// this.id = id;
// this.name = name;
// }
//
// public String getId() {
// return id;
// }
//
// public void setId(String id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// @Override
// public boolean equals(Object obj) {
// if(obj instanceof NameType) {
// NameType obj2 = (NameType) obj;
// return obj2.getId().equals(getId())
// && obj2.getName().equals(getName());
// }
// return false;
// }
// }
//
// Path: src/main/java/com/codefork/refine/resources/ServiceMetaDataResponse.java
// @JsonInclude(JsonInclude.Include.NON_NULL)
// public abstract class ServiceMetaDataResponse {
//
// private String name;
// private String identifierSpace;
// private String schemaSpace;
// private View view;
// private List<NameType> defaultTypes;
// private Preview preview;
// private Extend extend;
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public String getIdentifierSpace() {
// return identifierSpace;
// }
//
// public void setIdentifierSpace(String identifierSpace) {
// this.identifierSpace = identifierSpace;
// }
//
// public String getSchemaSpace() {
// return schemaSpace;
// }
//
// public void setSchemaSpace(String schemaSpace) {
// this.schemaSpace = schemaSpace;
// }
//
// public View getView() {
// return view;
// }
//
// public void setView(View view) {
// this.view = view;
// }
//
// public List<NameType> getDefaultTypes() {
// return defaultTypes;
// }
//
// public void setDefaultTypes(List<NameType> defaultTypes) {
// this.defaultTypes = defaultTypes;
// }
//
// public Preview getPreview() {
// return preview;
// }
//
// public void setPreview(Preview preview) {
// this.preview = preview;
// }
//
// public Extend getExtend() {
// return extend;
// }
//
// public void setExtend(Extend extend) {
// this.extend = extend;
// }
//
// }
//
// Path: src/main/java/com/codefork/refine/resources/View.java
// public class View {
// private String url;
//
// public View(String url) {
// this.url = url;
// }
//
// public String getUrl() {
// return url;
// }
//
// public void setUrl(String url) {
// this.url = url;
// }
//
// }
| import com.codefork.refine.resources.NameType;
import com.codefork.refine.resources.ServiceMetaDataResponse;
import com.codefork.refine.resources.View;
import com.fasterxml.jackson.annotation.JsonInclude;
import java.util.ArrayList;
import java.util.List; | package com.codefork.refine.openlibrary;
@JsonInclude(JsonInclude.Include.NON_NULL)
public class OpenLibraryMetaDataResponse extends ServiceMetaDataResponse {
private final static String IDENTIFIER_SPACE = "http://rdf.freebase.com/ns/user/hangy/viaf";
private final static View VIEW = new View("https://openlibrary.org{{id}}");
private final static String SCHEMA_SPACE = "http://rdf.freebase.com/ns/type.object.id"; | // Path: src/main/java/com/codefork/refine/resources/NameType.java
// public class NameType {
//
// private String id;
// private String name;
//
// public NameType(String id, String name) {
// this.id = id;
// this.name = name;
// }
//
// public String getId() {
// return id;
// }
//
// public void setId(String id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// @Override
// public boolean equals(Object obj) {
// if(obj instanceof NameType) {
// NameType obj2 = (NameType) obj;
// return obj2.getId().equals(getId())
// && obj2.getName().equals(getName());
// }
// return false;
// }
// }
//
// Path: src/main/java/com/codefork/refine/resources/ServiceMetaDataResponse.java
// @JsonInclude(JsonInclude.Include.NON_NULL)
// public abstract class ServiceMetaDataResponse {
//
// private String name;
// private String identifierSpace;
// private String schemaSpace;
// private View view;
// private List<NameType> defaultTypes;
// private Preview preview;
// private Extend extend;
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public String getIdentifierSpace() {
// return identifierSpace;
// }
//
// public void setIdentifierSpace(String identifierSpace) {
// this.identifierSpace = identifierSpace;
// }
//
// public String getSchemaSpace() {
// return schemaSpace;
// }
//
// public void setSchemaSpace(String schemaSpace) {
// this.schemaSpace = schemaSpace;
// }
//
// public View getView() {
// return view;
// }
//
// public void setView(View view) {
// this.view = view;
// }
//
// public List<NameType> getDefaultTypes() {
// return defaultTypes;
// }
//
// public void setDefaultTypes(List<NameType> defaultTypes) {
// this.defaultTypes = defaultTypes;
// }
//
// public Preview getPreview() {
// return preview;
// }
//
// public void setPreview(Preview preview) {
// this.preview = preview;
// }
//
// public Extend getExtend() {
// return extend;
// }
//
// public void setExtend(Extend extend) {
// this.extend = extend;
// }
//
// }
//
// Path: src/main/java/com/codefork/refine/resources/View.java
// public class View {
// private String url;
//
// public View(String url) {
// this.url = url;
// }
//
// public String getUrl() {
// return url;
// }
//
// public void setUrl(String url) {
// this.url = url;
// }
//
// }
// Path: src/main/java/com/codefork/refine/openlibrary/OpenLibraryMetaDataResponse.java
import com.codefork.refine.resources.NameType;
import com.codefork.refine.resources.ServiceMetaDataResponse;
import com.codefork.refine.resources.View;
import com.fasterxml.jackson.annotation.JsonInclude;
import java.util.ArrayList;
import java.util.List;
package com.codefork.refine.openlibrary;
@JsonInclude(JsonInclude.Include.NON_NULL)
public class OpenLibraryMetaDataResponse extends ServiceMetaDataResponse {
private final static String IDENTIFIER_SPACE = "http://rdf.freebase.com/ns/user/hangy/viaf";
private final static View VIEW = new View("https://openlibrary.org{{id}}");
private final static String SCHEMA_SPACE = "http://rdf.freebase.com/ns/type.object.id"; | private final static List<NameType> DEFAULT_TYPES = new ArrayList<>(); |
codeforkjeff/conciliator | src/main/java/com/codefork/refine/viaf/VIAFNameType.java | // Path: src/main/java/com/codefork/refine/resources/NameType.java
// public class NameType {
//
// private String id;
// private String name;
//
// public NameType(String id, String name) {
// this.id = id;
// this.name = name;
// }
//
// public String getId() {
// return id;
// }
//
// public void setId(String id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// @Override
// public boolean equals(Object obj) {
// if(obj instanceof NameType) {
// NameType obj2 = (NameType) obj;
// return obj2.getId().equals(getId())
// && obj2.getName().equals(getName());
// }
// return false;
// }
// }
| import com.codefork.refine.resources.NameType; |
package com.codefork.refine.viaf;
/**
* Different types of names. Note that this is for the application's internal
* use; see NameType (and the asNameType() method in this enum) for a
* class used to format data sent to VIAF.
*/
public enum VIAFNameType {
Person("/people/person", "Person", "Personal", "local.personalNames all \"%s\""),
Organization("/organization/organization", "Corporate Name", "Corporate", "local.corporateNames all \"%s\""),
Location("/location/location", "Geographic Name", "Geographic", "local.geographicNames all \"%s\""),
// can't find better freebase ids for these two
Book("/book/book", "Work", "UniformTitleWork", "local.uniformTitleWorks all \"%s\""),
Edition("/book/book edition", "Expression", "UniformTitleExpression", "local.uniformTitleExpressions all \"%s\"");
// ids are from freebase identifier ns
private final String id;
private final String displayName;
private final String viafCode;
private final String cqlString; | // Path: src/main/java/com/codefork/refine/resources/NameType.java
// public class NameType {
//
// private String id;
// private String name;
//
// public NameType(String id, String name) {
// this.id = id;
// this.name = name;
// }
//
// public String getId() {
// return id;
// }
//
// public void setId(String id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// @Override
// public boolean equals(Object obj) {
// if(obj instanceof NameType) {
// NameType obj2 = (NameType) obj;
// return obj2.getId().equals(getId())
// && obj2.getName().equals(getName());
// }
// return false;
// }
// }
// Path: src/main/java/com/codefork/refine/viaf/VIAFNameType.java
import com.codefork.refine.resources.NameType;
package com.codefork.refine.viaf;
/**
* Different types of names. Note that this is for the application's internal
* use; see NameType (and the asNameType() method in this enum) for a
* class used to format data sent to VIAF.
*/
public enum VIAFNameType {
Person("/people/person", "Person", "Personal", "local.personalNames all \"%s\""),
Organization("/organization/organization", "Corporate Name", "Corporate", "local.corporateNames all \"%s\""),
Location("/location/location", "Geographic Name", "Geographic", "local.geographicNames all \"%s\""),
// can't find better freebase ids for these two
Book("/book/book", "Work", "UniformTitleWork", "local.uniformTitleWorks all \"%s\""),
Edition("/book/book edition", "Expression", "UniformTitleExpression", "local.uniformTitleExpressions all \"%s\"");
// ids are from freebase identifier ns
private final String id;
private final String displayName;
private final String viafCode;
private final String cqlString; | private NameType nameType; |
codeforkjeff/conciliator | src/test/java/com/codefork/refine/orcid/OrcidParserTest.java | // Path: src/main/java/com/codefork/refine/resources/Result.java
// public class Result {
//
// private String id;
// private String name;
//
// /**
// * It's weird that this is a list but that's what OpenRefine expects.
// * A VIAF result only ever has one type, but maybe other reconciliation
// * services return multiple types for a name?
// */
// private List<NameType> type;
// private double score;
// private boolean match;
//
// public Result() {
// }
//
// public Result(String id, String name, NameType nameType, double score, boolean match) {
// this.id = id;
// this.name = name;
// this.type = new ArrayList<>();
// this.type.add(nameType);
// this.score = score;
// this.match = match;
// }
//
// public String getId() {
// return id;
// }
//
// public void setId(String id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public List<NameType> getType() {
// return type;
// }
//
// public void setType(List<NameType> resultType) {
// this.type = resultType;
// }
//
// public double getScore() {
// return score;
// }
//
// public void setScore(double score) {
// this.score = score;
// }
//
// public boolean isMatch() {
// return match;
// }
//
// public void setMatch(boolean match) {
// this.match = match;
// }
//
// }
| import com.codefork.refine.resources.Result;
import org.junit.Test;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import java.io.InputStream;
import java.util.List;
import static org.junit.Assert.assertEquals; | package com.codefork.refine.orcid;
public class OrcidParserTest {
@Test
public void testParseNames() throws Exception {
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser parser = spf.newSAXParser();
OrcidParser orcidParser = new OrcidParser();
InputStream is = getClass().getResourceAsStream("/orcid_results.xml");
parser.parse(is, orcidParser);
| // Path: src/main/java/com/codefork/refine/resources/Result.java
// public class Result {
//
// private String id;
// private String name;
//
// /**
// * It's weird that this is a list but that's what OpenRefine expects.
// * A VIAF result only ever has one type, but maybe other reconciliation
// * services return multiple types for a name?
// */
// private List<NameType> type;
// private double score;
// private boolean match;
//
// public Result() {
// }
//
// public Result(String id, String name, NameType nameType, double score, boolean match) {
// this.id = id;
// this.name = name;
// this.type = new ArrayList<>();
// this.type.add(nameType);
// this.score = score;
// this.match = match;
// }
//
// public String getId() {
// return id;
// }
//
// public void setId(String id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public List<NameType> getType() {
// return type;
// }
//
// public void setType(List<NameType> resultType) {
// this.type = resultType;
// }
//
// public double getScore() {
// return score;
// }
//
// public void setScore(double score) {
// this.score = score;
// }
//
// public boolean isMatch() {
// return match;
// }
//
// public void setMatch(boolean match) {
// this.match = match;
// }
//
// }
// Path: src/test/java/com/codefork/refine/orcid/OrcidParserTest.java
import com.codefork.refine.resources.Result;
import org.junit.Test;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import java.io.InputStream;
import java.util.List;
import static org.junit.Assert.assertEquals;
package com.codefork.refine.orcid;
public class OrcidParserTest {
@Test
public void testParseNames() throws Exception {
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser parser = spf.newSAXParser();
OrcidParser orcidParser = new OrcidParser();
InputStream is = getClass().getResourceAsStream("/orcid_results.xml");
parser.parse(is, orcidParser);
| List<Result> results = orcidParser.getResults(); |
codeforkjeff/conciliator | src/main/java/com/codefork/refine/parsers/ParseState.java | // Path: src/main/java/com/codefork/refine/resources/Result.java
// public class Result {
//
// private String id;
// private String name;
//
// /**
// * It's weird that this is a list but that's what OpenRefine expects.
// * A VIAF result only ever has one type, but maybe other reconciliation
// * services return multiple types for a name?
// */
// private List<NameType> type;
// private double score;
// private boolean match;
//
// public Result() {
// }
//
// public Result(String id, String name, NameType nameType, double score, boolean match) {
// this.id = id;
// this.name = name;
// this.type = new ArrayList<>();
// this.type.add(nameType);
// this.score = score;
// this.match = match;
// }
//
// public String getId() {
// return id;
// }
//
// public void setId(String id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public List<NameType> getType() {
// return type;
// }
//
// public void setType(List<NameType> resultType) {
// this.type = resultType;
// }
//
// public double getScore() {
// return score;
// }
//
// public void setScore(double score) {
// this.score = score;
// }
//
// public boolean isMatch() {
// return match;
// }
//
// public void setMatch(boolean match) {
// this.match = match;
// }
//
// }
| import com.codefork.refine.resources.Result;
import java.util.ArrayList;
import java.util.List; | package com.codefork.refine.parsers;
public class ParseState {
public boolean captureChars = false;
| // Path: src/main/java/com/codefork/refine/resources/Result.java
// public class Result {
//
// private String id;
// private String name;
//
// /**
// * It's weird that this is a list but that's what OpenRefine expects.
// * A VIAF result only ever has one type, but maybe other reconciliation
// * services return multiple types for a name?
// */
// private List<NameType> type;
// private double score;
// private boolean match;
//
// public Result() {
// }
//
// public Result(String id, String name, NameType nameType, double score, boolean match) {
// this.id = id;
// this.name = name;
// this.type = new ArrayList<>();
// this.type.add(nameType);
// this.score = score;
// this.match = match;
// }
//
// public String getId() {
// return id;
// }
//
// public void setId(String id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public List<NameType> getType() {
// return type;
// }
//
// public void setType(List<NameType> resultType) {
// this.type = resultType;
// }
//
// public double getScore() {
// return score;
// }
//
// public void setScore(double score) {
// this.score = score;
// }
//
// public boolean isMatch() {
// return match;
// }
//
// public void setMatch(boolean match) {
// this.match = match;
// }
//
// }
// Path: src/main/java/com/codefork/refine/parsers/ParseState.java
import com.codefork.refine.resources.Result;
import java.util.ArrayList;
import java.util.List;
package com.codefork.refine.parsers;
public class ParseState {
public boolean captureChars = false;
| public final List<Result> results = new ArrayList<>(); |
codeforkjeff/conciliator | src/main/java/com/codefork/refine/orcid/OrcidMetaDataResponse.java | // Path: src/main/java/com/codefork/refine/resources/NameType.java
// public class NameType {
//
// private String id;
// private String name;
//
// public NameType(String id, String name) {
// this.id = id;
// this.name = name;
// }
//
// public String getId() {
// return id;
// }
//
// public void setId(String id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// @Override
// public boolean equals(Object obj) {
// if(obj instanceof NameType) {
// NameType obj2 = (NameType) obj;
// return obj2.getId().equals(getId())
// && obj2.getName().equals(getName());
// }
// return false;
// }
// }
//
// Path: src/main/java/com/codefork/refine/resources/ServiceMetaDataResponse.java
// @JsonInclude(JsonInclude.Include.NON_NULL)
// public abstract class ServiceMetaDataResponse {
//
// private String name;
// private String identifierSpace;
// private String schemaSpace;
// private View view;
// private List<NameType> defaultTypes;
// private Preview preview;
// private Extend extend;
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public String getIdentifierSpace() {
// return identifierSpace;
// }
//
// public void setIdentifierSpace(String identifierSpace) {
// this.identifierSpace = identifierSpace;
// }
//
// public String getSchemaSpace() {
// return schemaSpace;
// }
//
// public void setSchemaSpace(String schemaSpace) {
// this.schemaSpace = schemaSpace;
// }
//
// public View getView() {
// return view;
// }
//
// public void setView(View view) {
// this.view = view;
// }
//
// public List<NameType> getDefaultTypes() {
// return defaultTypes;
// }
//
// public void setDefaultTypes(List<NameType> defaultTypes) {
// this.defaultTypes = defaultTypes;
// }
//
// public Preview getPreview() {
// return preview;
// }
//
// public void setPreview(Preview preview) {
// this.preview = preview;
// }
//
// public Extend getExtend() {
// return extend;
// }
//
// public void setExtend(Extend extend) {
// this.extend = extend;
// }
//
// }
//
// Path: src/main/java/com/codefork/refine/resources/View.java
// public class View {
// private String url;
//
// public View(String url) {
// this.url = url;
// }
//
// public String getUrl() {
// return url;
// }
//
// public void setUrl(String url) {
// this.url = url;
// }
//
// }
| import com.codefork.refine.resources.NameType;
import com.codefork.refine.resources.ServiceMetaDataResponse;
import com.codefork.refine.resources.View;
import com.fasterxml.jackson.annotation.JsonInclude;
import java.util.ArrayList;
import java.util.List; | package com.codefork.refine.orcid;
@JsonInclude(JsonInclude.Include.NON_NULL)
public class OrcidMetaDataResponse extends ServiceMetaDataResponse {
private final static String IDENTIFIER_SPACE = "http://xmlns.com/foaf/0.1/"; | // Path: src/main/java/com/codefork/refine/resources/NameType.java
// public class NameType {
//
// private String id;
// private String name;
//
// public NameType(String id, String name) {
// this.id = id;
// this.name = name;
// }
//
// public String getId() {
// return id;
// }
//
// public void setId(String id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// @Override
// public boolean equals(Object obj) {
// if(obj instanceof NameType) {
// NameType obj2 = (NameType) obj;
// return obj2.getId().equals(getId())
// && obj2.getName().equals(getName());
// }
// return false;
// }
// }
//
// Path: src/main/java/com/codefork/refine/resources/ServiceMetaDataResponse.java
// @JsonInclude(JsonInclude.Include.NON_NULL)
// public abstract class ServiceMetaDataResponse {
//
// private String name;
// private String identifierSpace;
// private String schemaSpace;
// private View view;
// private List<NameType> defaultTypes;
// private Preview preview;
// private Extend extend;
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public String getIdentifierSpace() {
// return identifierSpace;
// }
//
// public void setIdentifierSpace(String identifierSpace) {
// this.identifierSpace = identifierSpace;
// }
//
// public String getSchemaSpace() {
// return schemaSpace;
// }
//
// public void setSchemaSpace(String schemaSpace) {
// this.schemaSpace = schemaSpace;
// }
//
// public View getView() {
// return view;
// }
//
// public void setView(View view) {
// this.view = view;
// }
//
// public List<NameType> getDefaultTypes() {
// return defaultTypes;
// }
//
// public void setDefaultTypes(List<NameType> defaultTypes) {
// this.defaultTypes = defaultTypes;
// }
//
// public Preview getPreview() {
// return preview;
// }
//
// public void setPreview(Preview preview) {
// this.preview = preview;
// }
//
// public Extend getExtend() {
// return extend;
// }
//
// public void setExtend(Extend extend) {
// this.extend = extend;
// }
//
// }
//
// Path: src/main/java/com/codefork/refine/resources/View.java
// public class View {
// private String url;
//
// public View(String url) {
// this.url = url;
// }
//
// public String getUrl() {
// return url;
// }
//
// public void setUrl(String url) {
// this.url = url;
// }
//
// }
// Path: src/main/java/com/codefork/refine/orcid/OrcidMetaDataResponse.java
import com.codefork.refine.resources.NameType;
import com.codefork.refine.resources.ServiceMetaDataResponse;
import com.codefork.refine.resources.View;
import com.fasterxml.jackson.annotation.JsonInclude;
import java.util.ArrayList;
import java.util.List;
package com.codefork.refine.orcid;
@JsonInclude(JsonInclude.Include.NON_NULL)
public class OrcidMetaDataResponse extends ServiceMetaDataResponse {
private final static String IDENTIFIER_SPACE = "http://xmlns.com/foaf/0.1/"; | private final static View VIEW = new View("https://orcid.org/{{id}}"); |
codeforkjeff/conciliator | src/main/java/com/codefork/refine/orcid/OrcidMetaDataResponse.java | // Path: src/main/java/com/codefork/refine/resources/NameType.java
// public class NameType {
//
// private String id;
// private String name;
//
// public NameType(String id, String name) {
// this.id = id;
// this.name = name;
// }
//
// public String getId() {
// return id;
// }
//
// public void setId(String id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// @Override
// public boolean equals(Object obj) {
// if(obj instanceof NameType) {
// NameType obj2 = (NameType) obj;
// return obj2.getId().equals(getId())
// && obj2.getName().equals(getName());
// }
// return false;
// }
// }
//
// Path: src/main/java/com/codefork/refine/resources/ServiceMetaDataResponse.java
// @JsonInclude(JsonInclude.Include.NON_NULL)
// public abstract class ServiceMetaDataResponse {
//
// private String name;
// private String identifierSpace;
// private String schemaSpace;
// private View view;
// private List<NameType> defaultTypes;
// private Preview preview;
// private Extend extend;
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public String getIdentifierSpace() {
// return identifierSpace;
// }
//
// public void setIdentifierSpace(String identifierSpace) {
// this.identifierSpace = identifierSpace;
// }
//
// public String getSchemaSpace() {
// return schemaSpace;
// }
//
// public void setSchemaSpace(String schemaSpace) {
// this.schemaSpace = schemaSpace;
// }
//
// public View getView() {
// return view;
// }
//
// public void setView(View view) {
// this.view = view;
// }
//
// public List<NameType> getDefaultTypes() {
// return defaultTypes;
// }
//
// public void setDefaultTypes(List<NameType> defaultTypes) {
// this.defaultTypes = defaultTypes;
// }
//
// public Preview getPreview() {
// return preview;
// }
//
// public void setPreview(Preview preview) {
// this.preview = preview;
// }
//
// public Extend getExtend() {
// return extend;
// }
//
// public void setExtend(Extend extend) {
// this.extend = extend;
// }
//
// }
//
// Path: src/main/java/com/codefork/refine/resources/View.java
// public class View {
// private String url;
//
// public View(String url) {
// this.url = url;
// }
//
// public String getUrl() {
// return url;
// }
//
// public void setUrl(String url) {
// this.url = url;
// }
//
// }
| import com.codefork.refine.resources.NameType;
import com.codefork.refine.resources.ServiceMetaDataResponse;
import com.codefork.refine.resources.View;
import com.fasterxml.jackson.annotation.JsonInclude;
import java.util.ArrayList;
import java.util.List; | package com.codefork.refine.orcid;
@JsonInclude(JsonInclude.Include.NON_NULL)
public class OrcidMetaDataResponse extends ServiceMetaDataResponse {
private final static String IDENTIFIER_SPACE = "http://xmlns.com/foaf/0.1/";
private final static View VIEW = new View("https://orcid.org/{{id}}");
private final static String SCHEMA_SPACE = "http://rdf.freebase.com/ns/type.object.id"; | // Path: src/main/java/com/codefork/refine/resources/NameType.java
// public class NameType {
//
// private String id;
// private String name;
//
// public NameType(String id, String name) {
// this.id = id;
// this.name = name;
// }
//
// public String getId() {
// return id;
// }
//
// public void setId(String id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// @Override
// public boolean equals(Object obj) {
// if(obj instanceof NameType) {
// NameType obj2 = (NameType) obj;
// return obj2.getId().equals(getId())
// && obj2.getName().equals(getName());
// }
// return false;
// }
// }
//
// Path: src/main/java/com/codefork/refine/resources/ServiceMetaDataResponse.java
// @JsonInclude(JsonInclude.Include.NON_NULL)
// public abstract class ServiceMetaDataResponse {
//
// private String name;
// private String identifierSpace;
// private String schemaSpace;
// private View view;
// private List<NameType> defaultTypes;
// private Preview preview;
// private Extend extend;
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public String getIdentifierSpace() {
// return identifierSpace;
// }
//
// public void setIdentifierSpace(String identifierSpace) {
// this.identifierSpace = identifierSpace;
// }
//
// public String getSchemaSpace() {
// return schemaSpace;
// }
//
// public void setSchemaSpace(String schemaSpace) {
// this.schemaSpace = schemaSpace;
// }
//
// public View getView() {
// return view;
// }
//
// public void setView(View view) {
// this.view = view;
// }
//
// public List<NameType> getDefaultTypes() {
// return defaultTypes;
// }
//
// public void setDefaultTypes(List<NameType> defaultTypes) {
// this.defaultTypes = defaultTypes;
// }
//
// public Preview getPreview() {
// return preview;
// }
//
// public void setPreview(Preview preview) {
// this.preview = preview;
// }
//
// public Extend getExtend() {
// return extend;
// }
//
// public void setExtend(Extend extend) {
// this.extend = extend;
// }
//
// }
//
// Path: src/main/java/com/codefork/refine/resources/View.java
// public class View {
// private String url;
//
// public View(String url) {
// this.url = url;
// }
//
// public String getUrl() {
// return url;
// }
//
// public void setUrl(String url) {
// this.url = url;
// }
//
// }
// Path: src/main/java/com/codefork/refine/orcid/OrcidMetaDataResponse.java
import com.codefork.refine.resources.NameType;
import com.codefork.refine.resources.ServiceMetaDataResponse;
import com.codefork.refine.resources.View;
import com.fasterxml.jackson.annotation.JsonInclude;
import java.util.ArrayList;
import java.util.List;
package com.codefork.refine.orcid;
@JsonInclude(JsonInclude.Include.NON_NULL)
public class OrcidMetaDataResponse extends ServiceMetaDataResponse {
private final static String IDENTIFIER_SPACE = "http://xmlns.com/foaf/0.1/";
private final static View VIEW = new View("https://orcid.org/{{id}}");
private final static String SCHEMA_SPACE = "http://rdf.freebase.com/ns/type.object.id"; | private final static List<NameType> DEFAULT_TYPES = new ArrayList<>(); |
codeforkjeff/conciliator | src/main/java/com/codefork/refine/solr/AnotherSolr.java | // Path: src/main/java/com/codefork/refine/Config.java
// @Component
// public class Config {
//
// public static final String PROP_CACHE_ENABLED = "cache.enabled";
// public static final String PROP_CACHE_TTL = "cache.ttl";
// public static final String PROP_CACHE_SIZE = "cache.size";
//
// private static final String CONFIG_FILENAME = "conciliator.properties";
//
// private Log log = LogFactory.getLog(Config.class);
// private Properties properties = new Properties();
//
// public Config() {
// properties.put(PROP_CACHE_ENABLED, "true");
// properties.put(PROP_CACHE_TTL, "3600");
// properties.put(PROP_CACHE_SIZE, "64MB");
//
// properties.put("datasource.orcid.name", "ORCID");
// properties.put("datasource.orcidsmartnames.name", "ORCID - Smart Names Mode");
// properties.put("datasource.openlibrary.name", "OpenLibrary");
// loadFromFile();
// }
//
// public void loadFromFile() {
// if(new File(CONFIG_FILENAME).exists()) {
// try {
// log.info("Loading configuration from " + CONFIG_FILENAME);
// Properties p = new Properties();
// p.load(new FileInputStream(CONFIG_FILENAME));
// merge(p);
// } catch (IOException ex) {
// log.error("Error reading config file, skipping it: " + ex);
// }
// }
// }
//
// public void merge(Properties properties) {
// this.properties.putAll(properties);
// }
//
// public Properties getProperties() {
// return properties;
// }
//
// /**
// * Returns the properties relevant to a given data source name,
// * with the datasource.NAME prefix stripped off.
// *
// * e.g.
// * datasource.mysource.timeout=2000
// *
// * the Properties object returned will have key "timeout" with value "2000"
// *
// * @param name
// * @return
// */
// public Properties getDataSourceProperties(String name) {
// Properties props = new Properties();
// for(String key : getProperties().stringPropertyNames()) {
// String prefix = "datasource." + name;
// if(key.startsWith(prefix)) {
// String shortenedKey = key.substring(prefix.length()).replaceAll("^\\.+", "");
// if(shortenedKey.length() > 0) {
// props.setProperty(shortenedKey, getProperties().getProperty(key));
// }
// }
// }
// return props;
// }
//
// }
//
// Path: src/main/java/com/codefork/refine/ThreadPoolFactory.java
// @Component
// public class ThreadPoolFactory {
//
// private Map<String, ThreadPool> sharedThreadPools = new HashMap<>();
//
// public ThreadPool createThreadPool() {
// return new ThreadPool();
// }
//
// public ThreadPool getSharedThreadPool(String key) {
// if(!sharedThreadPools.containsKey(key)) {
// sharedThreadPools.put(key, new ThreadPool());
// }
// return sharedThreadPools.get(key);
// }
//
// public void releaseThreadPool(ThreadPool pool) {
// for(ThreadPool p: sharedThreadPools.values()) {
// if(p.equals(pool)) {
// // we never shut down shared thread pools.
// // TODO: keep a count of how many things use
// // a shared thread pool and release when 0.
// return;
// }
// }
// pool.shutdown();
// }
//
// }
//
// Path: src/main/java/com/codefork/refine/datasource/ConnectionFactory.java
// public interface ConnectionFactory {
//
// HttpURLConnection createConnection(String url) throws IOException;
//
// }
| import com.codefork.refine.Config;
import com.codefork.refine.ThreadPoolFactory;
import com.codefork.refine.datasource.ConnectionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.CacheManager;
import org.springframework.stereotype.Component; | package com.codefork.refine.solr;
/**
* Example of a second Solr data source. You can create as many solr data sources
* as you want, by copying/renaming this file.
*
* The name of this class doesn't actually matter, as long as it's unique and matches
* the .java filename.
*
* @Component specifies the name that Spring uses for injection; it should match the
* string in the @Qualifier annotation on DataSourceController.setDataSource().
*
* getConfigName() should return a name used for the keys in the conciliator.properties file.
*/
@Component("anothersolr")
public class AnotherSolr extends Solr {
@Autowired | // Path: src/main/java/com/codefork/refine/Config.java
// @Component
// public class Config {
//
// public static final String PROP_CACHE_ENABLED = "cache.enabled";
// public static final String PROP_CACHE_TTL = "cache.ttl";
// public static final String PROP_CACHE_SIZE = "cache.size";
//
// private static final String CONFIG_FILENAME = "conciliator.properties";
//
// private Log log = LogFactory.getLog(Config.class);
// private Properties properties = new Properties();
//
// public Config() {
// properties.put(PROP_CACHE_ENABLED, "true");
// properties.put(PROP_CACHE_TTL, "3600");
// properties.put(PROP_CACHE_SIZE, "64MB");
//
// properties.put("datasource.orcid.name", "ORCID");
// properties.put("datasource.orcidsmartnames.name", "ORCID - Smart Names Mode");
// properties.put("datasource.openlibrary.name", "OpenLibrary");
// loadFromFile();
// }
//
// public void loadFromFile() {
// if(new File(CONFIG_FILENAME).exists()) {
// try {
// log.info("Loading configuration from " + CONFIG_FILENAME);
// Properties p = new Properties();
// p.load(new FileInputStream(CONFIG_FILENAME));
// merge(p);
// } catch (IOException ex) {
// log.error("Error reading config file, skipping it: " + ex);
// }
// }
// }
//
// public void merge(Properties properties) {
// this.properties.putAll(properties);
// }
//
// public Properties getProperties() {
// return properties;
// }
//
// /**
// * Returns the properties relevant to a given data source name,
// * with the datasource.NAME prefix stripped off.
// *
// * e.g.
// * datasource.mysource.timeout=2000
// *
// * the Properties object returned will have key "timeout" with value "2000"
// *
// * @param name
// * @return
// */
// public Properties getDataSourceProperties(String name) {
// Properties props = new Properties();
// for(String key : getProperties().stringPropertyNames()) {
// String prefix = "datasource." + name;
// if(key.startsWith(prefix)) {
// String shortenedKey = key.substring(prefix.length()).replaceAll("^\\.+", "");
// if(shortenedKey.length() > 0) {
// props.setProperty(shortenedKey, getProperties().getProperty(key));
// }
// }
// }
// return props;
// }
//
// }
//
// Path: src/main/java/com/codefork/refine/ThreadPoolFactory.java
// @Component
// public class ThreadPoolFactory {
//
// private Map<String, ThreadPool> sharedThreadPools = new HashMap<>();
//
// public ThreadPool createThreadPool() {
// return new ThreadPool();
// }
//
// public ThreadPool getSharedThreadPool(String key) {
// if(!sharedThreadPools.containsKey(key)) {
// sharedThreadPools.put(key, new ThreadPool());
// }
// return sharedThreadPools.get(key);
// }
//
// public void releaseThreadPool(ThreadPool pool) {
// for(ThreadPool p: sharedThreadPools.values()) {
// if(p.equals(pool)) {
// // we never shut down shared thread pools.
// // TODO: keep a count of how many things use
// // a shared thread pool and release when 0.
// return;
// }
// }
// pool.shutdown();
// }
//
// }
//
// Path: src/main/java/com/codefork/refine/datasource/ConnectionFactory.java
// public interface ConnectionFactory {
//
// HttpURLConnection createConnection(String url) throws IOException;
//
// }
// Path: src/main/java/com/codefork/refine/solr/AnotherSolr.java
import com.codefork.refine.Config;
import com.codefork.refine.ThreadPoolFactory;
import com.codefork.refine.datasource.ConnectionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.CacheManager;
import org.springframework.stereotype.Component;
package com.codefork.refine.solr;
/**
* Example of a second Solr data source. You can create as many solr data sources
* as you want, by copying/renaming this file.
*
* The name of this class doesn't actually matter, as long as it's unique and matches
* the .java filename.
*
* @Component specifies the name that Spring uses for injection; it should match the
* string in the @Qualifier annotation on DataSourceController.setDataSource().
*
* getConfigName() should return a name used for the keys in the conciliator.properties file.
*/
@Component("anothersolr")
public class AnotherSolr extends Solr {
@Autowired | public AnotherSolr(Config config, CacheManager cacheManager, ThreadPoolFactory threadPoolFactory, ConnectionFactory connectionFactory) { |
codeforkjeff/conciliator | src/main/java/com/codefork/refine/solr/AnotherSolr.java | // Path: src/main/java/com/codefork/refine/Config.java
// @Component
// public class Config {
//
// public static final String PROP_CACHE_ENABLED = "cache.enabled";
// public static final String PROP_CACHE_TTL = "cache.ttl";
// public static final String PROP_CACHE_SIZE = "cache.size";
//
// private static final String CONFIG_FILENAME = "conciliator.properties";
//
// private Log log = LogFactory.getLog(Config.class);
// private Properties properties = new Properties();
//
// public Config() {
// properties.put(PROP_CACHE_ENABLED, "true");
// properties.put(PROP_CACHE_TTL, "3600");
// properties.put(PROP_CACHE_SIZE, "64MB");
//
// properties.put("datasource.orcid.name", "ORCID");
// properties.put("datasource.orcidsmartnames.name", "ORCID - Smart Names Mode");
// properties.put("datasource.openlibrary.name", "OpenLibrary");
// loadFromFile();
// }
//
// public void loadFromFile() {
// if(new File(CONFIG_FILENAME).exists()) {
// try {
// log.info("Loading configuration from " + CONFIG_FILENAME);
// Properties p = new Properties();
// p.load(new FileInputStream(CONFIG_FILENAME));
// merge(p);
// } catch (IOException ex) {
// log.error("Error reading config file, skipping it: " + ex);
// }
// }
// }
//
// public void merge(Properties properties) {
// this.properties.putAll(properties);
// }
//
// public Properties getProperties() {
// return properties;
// }
//
// /**
// * Returns the properties relevant to a given data source name,
// * with the datasource.NAME prefix stripped off.
// *
// * e.g.
// * datasource.mysource.timeout=2000
// *
// * the Properties object returned will have key "timeout" with value "2000"
// *
// * @param name
// * @return
// */
// public Properties getDataSourceProperties(String name) {
// Properties props = new Properties();
// for(String key : getProperties().stringPropertyNames()) {
// String prefix = "datasource." + name;
// if(key.startsWith(prefix)) {
// String shortenedKey = key.substring(prefix.length()).replaceAll("^\\.+", "");
// if(shortenedKey.length() > 0) {
// props.setProperty(shortenedKey, getProperties().getProperty(key));
// }
// }
// }
// return props;
// }
//
// }
//
// Path: src/main/java/com/codefork/refine/ThreadPoolFactory.java
// @Component
// public class ThreadPoolFactory {
//
// private Map<String, ThreadPool> sharedThreadPools = new HashMap<>();
//
// public ThreadPool createThreadPool() {
// return new ThreadPool();
// }
//
// public ThreadPool getSharedThreadPool(String key) {
// if(!sharedThreadPools.containsKey(key)) {
// sharedThreadPools.put(key, new ThreadPool());
// }
// return sharedThreadPools.get(key);
// }
//
// public void releaseThreadPool(ThreadPool pool) {
// for(ThreadPool p: sharedThreadPools.values()) {
// if(p.equals(pool)) {
// // we never shut down shared thread pools.
// // TODO: keep a count of how many things use
// // a shared thread pool and release when 0.
// return;
// }
// }
// pool.shutdown();
// }
//
// }
//
// Path: src/main/java/com/codefork/refine/datasource/ConnectionFactory.java
// public interface ConnectionFactory {
//
// HttpURLConnection createConnection(String url) throws IOException;
//
// }
| import com.codefork.refine.Config;
import com.codefork.refine.ThreadPoolFactory;
import com.codefork.refine.datasource.ConnectionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.CacheManager;
import org.springframework.stereotype.Component; | package com.codefork.refine.solr;
/**
* Example of a second Solr data source. You can create as many solr data sources
* as you want, by copying/renaming this file.
*
* The name of this class doesn't actually matter, as long as it's unique and matches
* the .java filename.
*
* @Component specifies the name that Spring uses for injection; it should match the
* string in the @Qualifier annotation on DataSourceController.setDataSource().
*
* getConfigName() should return a name used for the keys in the conciliator.properties file.
*/
@Component("anothersolr")
public class AnotherSolr extends Solr {
@Autowired | // Path: src/main/java/com/codefork/refine/Config.java
// @Component
// public class Config {
//
// public static final String PROP_CACHE_ENABLED = "cache.enabled";
// public static final String PROP_CACHE_TTL = "cache.ttl";
// public static final String PROP_CACHE_SIZE = "cache.size";
//
// private static final String CONFIG_FILENAME = "conciliator.properties";
//
// private Log log = LogFactory.getLog(Config.class);
// private Properties properties = new Properties();
//
// public Config() {
// properties.put(PROP_CACHE_ENABLED, "true");
// properties.put(PROP_CACHE_TTL, "3600");
// properties.put(PROP_CACHE_SIZE, "64MB");
//
// properties.put("datasource.orcid.name", "ORCID");
// properties.put("datasource.orcidsmartnames.name", "ORCID - Smart Names Mode");
// properties.put("datasource.openlibrary.name", "OpenLibrary");
// loadFromFile();
// }
//
// public void loadFromFile() {
// if(new File(CONFIG_FILENAME).exists()) {
// try {
// log.info("Loading configuration from " + CONFIG_FILENAME);
// Properties p = new Properties();
// p.load(new FileInputStream(CONFIG_FILENAME));
// merge(p);
// } catch (IOException ex) {
// log.error("Error reading config file, skipping it: " + ex);
// }
// }
// }
//
// public void merge(Properties properties) {
// this.properties.putAll(properties);
// }
//
// public Properties getProperties() {
// return properties;
// }
//
// /**
// * Returns the properties relevant to a given data source name,
// * with the datasource.NAME prefix stripped off.
// *
// * e.g.
// * datasource.mysource.timeout=2000
// *
// * the Properties object returned will have key "timeout" with value "2000"
// *
// * @param name
// * @return
// */
// public Properties getDataSourceProperties(String name) {
// Properties props = new Properties();
// for(String key : getProperties().stringPropertyNames()) {
// String prefix = "datasource." + name;
// if(key.startsWith(prefix)) {
// String shortenedKey = key.substring(prefix.length()).replaceAll("^\\.+", "");
// if(shortenedKey.length() > 0) {
// props.setProperty(shortenedKey, getProperties().getProperty(key));
// }
// }
// }
// return props;
// }
//
// }
//
// Path: src/main/java/com/codefork/refine/ThreadPoolFactory.java
// @Component
// public class ThreadPoolFactory {
//
// private Map<String, ThreadPool> sharedThreadPools = new HashMap<>();
//
// public ThreadPool createThreadPool() {
// return new ThreadPool();
// }
//
// public ThreadPool getSharedThreadPool(String key) {
// if(!sharedThreadPools.containsKey(key)) {
// sharedThreadPools.put(key, new ThreadPool());
// }
// return sharedThreadPools.get(key);
// }
//
// public void releaseThreadPool(ThreadPool pool) {
// for(ThreadPool p: sharedThreadPools.values()) {
// if(p.equals(pool)) {
// // we never shut down shared thread pools.
// // TODO: keep a count of how many things use
// // a shared thread pool and release when 0.
// return;
// }
// }
// pool.shutdown();
// }
//
// }
//
// Path: src/main/java/com/codefork/refine/datasource/ConnectionFactory.java
// public interface ConnectionFactory {
//
// HttpURLConnection createConnection(String url) throws IOException;
//
// }
// Path: src/main/java/com/codefork/refine/solr/AnotherSolr.java
import com.codefork.refine.Config;
import com.codefork.refine.ThreadPoolFactory;
import com.codefork.refine.datasource.ConnectionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.CacheManager;
import org.springframework.stereotype.Component;
package com.codefork.refine.solr;
/**
* Example of a second Solr data source. You can create as many solr data sources
* as you want, by copying/renaming this file.
*
* The name of this class doesn't actually matter, as long as it's unique and matches
* the .java filename.
*
* @Component specifies the name that Spring uses for injection; it should match the
* string in the @Qualifier annotation on DataSourceController.setDataSource().
*
* getConfigName() should return a name used for the keys in the conciliator.properties file.
*/
@Component("anothersolr")
public class AnotherSolr extends Solr {
@Autowired | public AnotherSolr(Config config, CacheManager cacheManager, ThreadPoolFactory threadPoolFactory, ConnectionFactory connectionFactory) { |
codeforkjeff/conciliator | src/main/java/com/codefork/refine/solr/AnotherSolr.java | // Path: src/main/java/com/codefork/refine/Config.java
// @Component
// public class Config {
//
// public static final String PROP_CACHE_ENABLED = "cache.enabled";
// public static final String PROP_CACHE_TTL = "cache.ttl";
// public static final String PROP_CACHE_SIZE = "cache.size";
//
// private static final String CONFIG_FILENAME = "conciliator.properties";
//
// private Log log = LogFactory.getLog(Config.class);
// private Properties properties = new Properties();
//
// public Config() {
// properties.put(PROP_CACHE_ENABLED, "true");
// properties.put(PROP_CACHE_TTL, "3600");
// properties.put(PROP_CACHE_SIZE, "64MB");
//
// properties.put("datasource.orcid.name", "ORCID");
// properties.put("datasource.orcidsmartnames.name", "ORCID - Smart Names Mode");
// properties.put("datasource.openlibrary.name", "OpenLibrary");
// loadFromFile();
// }
//
// public void loadFromFile() {
// if(new File(CONFIG_FILENAME).exists()) {
// try {
// log.info("Loading configuration from " + CONFIG_FILENAME);
// Properties p = new Properties();
// p.load(new FileInputStream(CONFIG_FILENAME));
// merge(p);
// } catch (IOException ex) {
// log.error("Error reading config file, skipping it: " + ex);
// }
// }
// }
//
// public void merge(Properties properties) {
// this.properties.putAll(properties);
// }
//
// public Properties getProperties() {
// return properties;
// }
//
// /**
// * Returns the properties relevant to a given data source name,
// * with the datasource.NAME prefix stripped off.
// *
// * e.g.
// * datasource.mysource.timeout=2000
// *
// * the Properties object returned will have key "timeout" with value "2000"
// *
// * @param name
// * @return
// */
// public Properties getDataSourceProperties(String name) {
// Properties props = new Properties();
// for(String key : getProperties().stringPropertyNames()) {
// String prefix = "datasource." + name;
// if(key.startsWith(prefix)) {
// String shortenedKey = key.substring(prefix.length()).replaceAll("^\\.+", "");
// if(shortenedKey.length() > 0) {
// props.setProperty(shortenedKey, getProperties().getProperty(key));
// }
// }
// }
// return props;
// }
//
// }
//
// Path: src/main/java/com/codefork/refine/ThreadPoolFactory.java
// @Component
// public class ThreadPoolFactory {
//
// private Map<String, ThreadPool> sharedThreadPools = new HashMap<>();
//
// public ThreadPool createThreadPool() {
// return new ThreadPool();
// }
//
// public ThreadPool getSharedThreadPool(String key) {
// if(!sharedThreadPools.containsKey(key)) {
// sharedThreadPools.put(key, new ThreadPool());
// }
// return sharedThreadPools.get(key);
// }
//
// public void releaseThreadPool(ThreadPool pool) {
// for(ThreadPool p: sharedThreadPools.values()) {
// if(p.equals(pool)) {
// // we never shut down shared thread pools.
// // TODO: keep a count of how many things use
// // a shared thread pool and release when 0.
// return;
// }
// }
// pool.shutdown();
// }
//
// }
//
// Path: src/main/java/com/codefork/refine/datasource/ConnectionFactory.java
// public interface ConnectionFactory {
//
// HttpURLConnection createConnection(String url) throws IOException;
//
// }
| import com.codefork.refine.Config;
import com.codefork.refine.ThreadPoolFactory;
import com.codefork.refine.datasource.ConnectionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.CacheManager;
import org.springframework.stereotype.Component; | package com.codefork.refine.solr;
/**
* Example of a second Solr data source. You can create as many solr data sources
* as you want, by copying/renaming this file.
*
* The name of this class doesn't actually matter, as long as it's unique and matches
* the .java filename.
*
* @Component specifies the name that Spring uses for injection; it should match the
* string in the @Qualifier annotation on DataSourceController.setDataSource().
*
* getConfigName() should return a name used for the keys in the conciliator.properties file.
*/
@Component("anothersolr")
public class AnotherSolr extends Solr {
@Autowired | // Path: src/main/java/com/codefork/refine/Config.java
// @Component
// public class Config {
//
// public static final String PROP_CACHE_ENABLED = "cache.enabled";
// public static final String PROP_CACHE_TTL = "cache.ttl";
// public static final String PROP_CACHE_SIZE = "cache.size";
//
// private static final String CONFIG_FILENAME = "conciliator.properties";
//
// private Log log = LogFactory.getLog(Config.class);
// private Properties properties = new Properties();
//
// public Config() {
// properties.put(PROP_CACHE_ENABLED, "true");
// properties.put(PROP_CACHE_TTL, "3600");
// properties.put(PROP_CACHE_SIZE, "64MB");
//
// properties.put("datasource.orcid.name", "ORCID");
// properties.put("datasource.orcidsmartnames.name", "ORCID - Smart Names Mode");
// properties.put("datasource.openlibrary.name", "OpenLibrary");
// loadFromFile();
// }
//
// public void loadFromFile() {
// if(new File(CONFIG_FILENAME).exists()) {
// try {
// log.info("Loading configuration from " + CONFIG_FILENAME);
// Properties p = new Properties();
// p.load(new FileInputStream(CONFIG_FILENAME));
// merge(p);
// } catch (IOException ex) {
// log.error("Error reading config file, skipping it: " + ex);
// }
// }
// }
//
// public void merge(Properties properties) {
// this.properties.putAll(properties);
// }
//
// public Properties getProperties() {
// return properties;
// }
//
// /**
// * Returns the properties relevant to a given data source name,
// * with the datasource.NAME prefix stripped off.
// *
// * e.g.
// * datasource.mysource.timeout=2000
// *
// * the Properties object returned will have key "timeout" with value "2000"
// *
// * @param name
// * @return
// */
// public Properties getDataSourceProperties(String name) {
// Properties props = new Properties();
// for(String key : getProperties().stringPropertyNames()) {
// String prefix = "datasource." + name;
// if(key.startsWith(prefix)) {
// String shortenedKey = key.substring(prefix.length()).replaceAll("^\\.+", "");
// if(shortenedKey.length() > 0) {
// props.setProperty(shortenedKey, getProperties().getProperty(key));
// }
// }
// }
// return props;
// }
//
// }
//
// Path: src/main/java/com/codefork/refine/ThreadPoolFactory.java
// @Component
// public class ThreadPoolFactory {
//
// private Map<String, ThreadPool> sharedThreadPools = new HashMap<>();
//
// public ThreadPool createThreadPool() {
// return new ThreadPool();
// }
//
// public ThreadPool getSharedThreadPool(String key) {
// if(!sharedThreadPools.containsKey(key)) {
// sharedThreadPools.put(key, new ThreadPool());
// }
// return sharedThreadPools.get(key);
// }
//
// public void releaseThreadPool(ThreadPool pool) {
// for(ThreadPool p: sharedThreadPools.values()) {
// if(p.equals(pool)) {
// // we never shut down shared thread pools.
// // TODO: keep a count of how many things use
// // a shared thread pool and release when 0.
// return;
// }
// }
// pool.shutdown();
// }
//
// }
//
// Path: src/main/java/com/codefork/refine/datasource/ConnectionFactory.java
// public interface ConnectionFactory {
//
// HttpURLConnection createConnection(String url) throws IOException;
//
// }
// Path: src/main/java/com/codefork/refine/solr/AnotherSolr.java
import com.codefork.refine.Config;
import com.codefork.refine.ThreadPoolFactory;
import com.codefork.refine.datasource.ConnectionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.CacheManager;
import org.springframework.stereotype.Component;
package com.codefork.refine.solr;
/**
* Example of a second Solr data source. You can create as many solr data sources
* as you want, by copying/renaming this file.
*
* The name of this class doesn't actually matter, as long as it's unique and matches
* the .java filename.
*
* @Component specifies the name that Spring uses for injection; it should match the
* string in the @Qualifier annotation on DataSourceController.setDataSource().
*
* getConfigName() should return a name used for the keys in the conciliator.properties file.
*/
@Component("anothersolr")
public class AnotherSolr extends Solr {
@Autowired | public AnotherSolr(Config config, CacheManager cacheManager, ThreadPoolFactory threadPoolFactory, ConnectionFactory connectionFactory) { |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.